Making a DLL COM accessible
Asked Answered
S

4

7

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

  1. I Created a Class Library Project in Visual Studio 2010 Express and put the code in a Class Module.
  2. I opened the project properties and went to "Assembly Information" and checked "Make COM Visible".
  3. I went to "Advanced Compile" options and targeted .Net 2.0 (it's very simple code).
  4. I then removed all references expect for "System".
  5. I built the project (no warnings or errors) and copied the DLL out of the Bin folder into C:\Windows\System32\
  6. I ran RegSvr32 to register the DLL and got the error:

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

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

Clearly my first attempt was a bit naive. Could someone offer guidance?

Sharpnosed answered 27/7, 2010 at 18:20 Comment(1)
regsvr32 can't be used on .NET assemblies. Use regasm and optional arguments - msdn.microsoft.com/en-us/library/tzat5yw6%28VS.71%29.aspxBlazon
R
10

Step #6 is wrong. .NET assemblies with [ComVisible] types are registered with Regasm.exe. Use the /codebase command line option if you don't want to install the DLL into the GAC. The /tlb command line option creates the type library, you can use that in your VB6 project.

Rangefinder answered 27/7, 2010 at 18:29 Comment(4)
I did a file search for regasm.exe and it seems to be missing. Is this only available with the full version of Visual Studio? Does MS offer a download (I am still googling, but I thought you might just know.)Sharpnosed
It should be in the c:\windows\microsoft.net\framework\v4.0.30319 directory. You are missing the "Visual Studio Command Prompt" to make this easy. But it can be done.Rangefinder
OK I found RegAsm and used it. This created a tlb that I could reference. When I opened it in VB6/VBA all the properties and methods were missing. By reading through some of the other links provided I infer that I need to create an interface (something I did not do, I just created the class). I'm still tweaking the interface but this was a major step. Thank you.Sharpnosed
Accepted as this actually got me to where I needed to be.Sharpnosed
H
3

You'll need to define GUIDs for your interfaces and mark which classes implement which interfaces, to start. MSDN has a getting started guide. You don't need to run RegSvr32, but you do need to put the DLL somewhere where the app 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 only going to be activated by a single application, you can place it in that application's directory.

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

Headon answered 27/7, 2010 at 18:30 Comment(0)
S
0

I am fairly certain RegSvr32 only works on non.NET DLL. .NET assemblies are stored in the Global Assembly Cache (GAC). You have to run the gacutil.exe.

Swaziland answered 27/7, 2010 at 18:24 Comment(1)
Putting them into GAC is not necessary. regasm with /codebase key will be just fine.Blaineblainey
B
0

Use GacUtil instead of RegSvr32. RegSvr is used for dll's made with VB6 and for the .NET DLL's you need to use GacUtil because it is added to the global assembly cache.

Bushmaster answered 29/1, 2015 at 14:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.