VB 6.0 で CLR をホストするコード

ちょっとワケあって、Essential .NET から転載しておく。

Private Sub Form_Load()
    Dim rt As mscoree.CorRuntimeHost
    Dim unk As stdole.IUnknown
    Dim ad As mscorlib.AppDomain
    Dim s As mscorlib.Stack
    Set rt = New mscoree.CorRuntimeHost
    rt.Start
    rt.GetDefaultDomain unk
    Set ad = unk
    Set s = ad.CreateInstance("mscorlib", "System.Collections.Stack").Unwrap
    s.Push "Hello"
    s.Push "Goodbye"
    s.Push 42
    MsgBox s.Pop()
    MsgBox s.Pop()
    MsgBox s.Pop()
End Sub

次の二つを参照設定する必要あり。

  • mscoree.tlb
  • mscorlib.tlb


Essential .NET ― 共通言語ランタイムの本質

Essential .NET ― 共通言語ランタイムの本質