Creating an Accessible DLL

I have a class library written in .Net that I would like to make available for VB6 / VBA. What I tried did not work (obviously, as I ask this question). Here is what I did:

  • I created a class library project in Visual Studio 2010 Express and put the code in a class module.
  • I opened the project properties and went to "Assembly Information" and checked the "Make COM Visible" checkbox.
  • I went to the "Advanced Compile" option and targeted .Net 2.0 (this is very simple code).
  • Then I deleted all the links for the "System".
  • I built a project (no warnings or errors) and copied the DLL from the Bin folder to C: \ Windows \ System32 \
  • I ran RegSvr32 to register the dll and got an error:

The module "MyDll.dll" was loaded, but the entry point DLLRegisterServer was not found.

Verify that "MyDll.dll is a valid DLL or OCX file, and then try again.

Clearly, my first attempt was a bit naive. Can anyone suggest a guide?

+7
vb6 vb6-migration com
source share
4 answers

Step 6 is incorrect. .NET assemblies with types [ComVisible] are registered in Regasm.exe. Use the / codebase command line option if you do not want to install the DLL in the GAC. The / tlb command-line option creates a type library, you can use it in your VB6 project.

+10
source share

You will need to define a GUID for your interfaces and note which classes implement the interfaces to get started. MSDN has a getting started guide . You do not need to run RegSvr32, but you need to place the DLL somewhere where the application can find it :

After registering an assembly using Regasm.exe, you can install it in the global assembly cache so that it can be activated from any COM client. If the assembly is activated by only one application, you can place it in this application directory.

There is also a good overview of the whole process here .

+3
source share

I'm pretty sure RegSvr32 only works with non-NET DLLs. .NET assemblies are stored in the global assembly cache (GAC). You need to run gacutil.exe.

0
source share

Use GacUtil instead of RegSvr32. RegSvr is used for a dll created using VB6, and for the .NET DLL you need to use GacUtil because it is added to the global build cache.

0
source share

All Articles