"Call VB6 From .NET" by Rockford Lhotka
Visual Studio Magazine, April 2002


The code for this article is divided into four parts.

comclient:

This is the code for a VB6 COM client application that makes use of the NETdll project. Before attempting to run comclient, you need to first compile the NETdll project as discussed in the article - making sure that a COM type library is exported and referenced in the Windows registry. Though comclient contains a reference to the NETdll component, you may need to remove and re-add this reference after compiling the .NET component on your system.

You can change this to create a NETclass2 object instead in order to test the manual implementation of the interfaces.


comdll:

This is the code for a VB6 COM DLL that can be called from .NET. It is this DLL that is called by the NETclient project. Before attempting to run NETclient, you should recompile this project, or at least use the regsvr32.exe command line utility to register the existing DLL on your system.


NETclient:

This is the code for a .NET client application that makes use of the comdll project. Before attempting to run NETclient, you need first to compile the comdll project or register it by using the regsvr32.exe command line utility. You may also need to remove and re-add the reference to the COM component from within the project.


NETdll:

This is the code for a .NET DLL that can be called from VB6. It is this DLL that is called by the comclient project. Before attempting to run comclient, you should recompile this project, or at least use the regasm.exe command line utility to register the existing DLL on your system. Before rebuilding the DLL, make sure you read the article and set the projects properties as appropriate to ensure that a COM type library is created and registered on your system.

This project also includes NETclass2, which is the manual implementation of the interfaces for COM interop. NETclass itself uses the <ComClass()> attribute that does all the work for us automatically.
