Is it possible to late bind to a dll written in C# from VB6? If so, does
anyone have an example.
Rob Windsor - 23 Sep 2003 16:06 GMT
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/default.asp?url=/library/en-us/csref/html/vcwl
kcominteroppart2cservertutorial.asp
.NET Framework Developer's Guide
Exposing .NET Framework Components to COM
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cp
conexposingnetframeworkcomponentstocom.asp

Signature
Rob Windsor
G6 Consulting
Toronto, Canada
> Is it possible to late bind to a dll written in C# from VB6? If so, does
> anyone have an example.
Vadim Melnik - 24 Sep 2003 23:33 GMT
Hi,
> Is it possible to late bind to a dll written in C# from VB6? If so, does
> anyone have an example.
It's possible but you need somehow instantiate this object. mscoree.dll
exposes undocumented ClrCreateManagedInstance function, it's declared in
mscoree.h as the following:
STDAPI ClrCreateManagedInstance(LPCWSTR pTypeName, REFIID riid, void
**ppObject);
and C++ usage:
HRESULT hr = ClrCreateManagedInstance(L"ClrTestLib.CFoo, ClrTestLib,
Version=1.0.1207.27541, Culture=neutral, PublicKeyToken=a8c61b7e4c98192e",
IID_IUnknown, reinterpret_cast<void**>(&spUnk));
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 CorBindToRuntimeEx call, then Start it, and then create or
retrieve default domain by ICorRuntimeHost::CreateDomain/GetDefaultDomain,
and after use it to instantiate class instance - e.g.
AppDomain.CreateInstanceFrom.
..
Cheers,
Vadim.
Phil Wilson - 25 Sep 2003 16:05 GMT
If you mean classic late binding as in VB CreateObject("Progid") and
IDispatch-based calls, start with Type.GetTypeFromProgID.

Signature
Phil Wilson [MVP Windows Installer]
> Is it possible to late bind to a dll written in C# from VB6? If so, does
> anyone have an example.