Late Binding

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Justin Starnes

    #1

    Late Binding

    Is it possible to late bind to a dll written in C# from VB6? If so, does
    anyone have an example.


  • Rob Windsor

    #2
    Re: Late Binding

    Yes, you need to use COM Interop. Here are some links.


    C# Programmer's Reference
    COM Interop Part 2: C# Server Tutorial
    http://msdn.microsoft.com/library/de...ertutorial.asp

    ..NET Framework Developer's Guide
    Exposing .NET Framework Components to COM
    http://msdn.microsoft.com/library/de...nentstocom.asp

    --
    Rob Windsor
    G6 Consulting
    Toronto, Canada


    "Justin Starnes" <jlstarnes@char tertn.net> wrote in message
    news:%23nEdYLYg DHA.2748@TK2MSF TNGP11.phx.gbl. ..[color=blue]
    > Is it possible to late bind to a dll written in C# from VB6? If so, does
    > anyone have an example.
    >
    >[/color]


    Comment

    • Vadim Melnik

      #3
      Re: Late Binding

      Hi,
      [color=blue]
      > Is it possible to late bind to a dll written in C# from VB6? If so, does
      > anyone have an example.[/color]

      It's possible but you need somehow instantiate this object. mscoree.dll
      exposes undocumented ClrCreateManage dInstance function, it's declared in
      mscoree.h as the following:

      STDAPI ClrCreateManage dInstance(LPCWS TR pTypeName, REFIID riid, void
      **ppObject);

      and C++ usage:

      HRESULT hr = ClrCreateManage dInstance(L"Clr TestLib.CFoo, ClrTestLib,
      Version=1.0.120 7.27541, Culture=neutral , PublicKeyToken= a8c61b7e4c98192 e",
      IID_IUnknown, reinterpret_cas t<void**>(&spUn k));


      Or you can use technique described in "Microsoft .NET: Implement a Custom
      Common Language Runtime Host for Your Managed App" MSDN Magazine article to
      create CLR by CorBindToRuntim eEx call, then Start it, and then create or
      retrieve default domain by ICorRuntimeHost ::CreateDomain/GetDefaultDomai n,
      and after use it to instantiate class instance - e.g.
      AppDomain.Creat eInstanceFrom.

      ...
      Cheers,
      Vadim.



      Comment

      • Vadim Melnik

        #4
        Re: Late Binding

        Hi,
        [color=blue]
        > Is it possible to late bind to a dll written in C# from VB6? If so, does
        > anyone have an example.[/color]

        It's possible but you need somehow instantiate this object. mscoree.dll
        exposes undocumented ClrCreateManage dInstance function, it's declared in
        mscoree.h as the following:

        STDAPI ClrCreateManage dInstance(LPCWS TR pTypeName, REFIID riid, void
        **ppObject);

        and C++ usage:

        HRESULT hr = ClrCreateManage dInstance(L"Clr TestLib.CFoo, ClrTestLib,
        Version=1.0.120 7.27541, Culture=neutral , PublicKeyToken= a8c61b7e4c98192 e",
        IID_IUnknown, reinterpret_cas t<void**>(&spUn k));


        Or you can use technique described in "Microsoft .NET: Implement a Custom
        Common Language Runtime Host for Your Managed App" MSDN Magazine article to
        create CLR by CorBindToRuntim eEx call, then Start it, and then create or
        retrieve default domain by ICorRuntimeHost ::CreateDomain/GetDefaultDomai n,
        and after use it to instantiate class instance - e.g.
        AppDomain.Creat eInstanceFrom.

        ...
        Cheers,
        Vadim.



        Comment

        • Phil Wilson

          #5
          Re: Late Binding

          If you mean classic late binding as in VB CreateObject("P rogid") and
          IDispatch-based calls, start with Type.GetTypeFro mProgID.
          --
          Phil Wilson [MVP Windows Installer]

          "Justin Starnes" <jlstarnes@char tertn.net> wrote in message
          news:%23nEdYLYg DHA.2748@TK2MSF TNGP11.phx.gbl. ..[color=blue]
          > Is it possible to late bind to a dll written in C# from VB6? If so, does
          > anyone have an example.
          >
          >[/color]


          Comment

          Working...