Register .NET dll for use in VB6 application

I have a DLL that I wrote in C # that I want to use in my VB6 application.

In VS2008, the project property "Register for COM interop" is checked, and when I compile a DLL and try to use it on my development machine, it works fine.

I need to run it on a computer that does not have VS2008, so I tried to register this DLL as follows:

C:\WINDOWS\system32>..\Microsoft.NET\Framework\v2.0.50727\regasm myDLL.dll /tlb: myDLL.tlb /codebase 

but then when I try to run it, I get this error:

Automation Error. The system cannot find the specified file.

Can anyone tell me what I'm doing wrong?

+7
source share
2 answers

Just as you specified the full path to regasm.exe, you need to specify the full path to your .dll; -)

+4
source

The reason this happens is because you did not assign a GUID to your classes. Your class in .NET should be styled as follows:

 [GuidAttribute("BA713700-522D-466e-8DD4-225884504678")] public class MyClass 

This way, your class will be compiled with the same GUID attribute each time regasm starts. If you do not include this attribute, regasm will automatically assign a different GUID each time.

To be completely safe, your class must inherit from the interface

 [Guid("9AC71CA7-6F82-44A3-9ABE-75354B514A46")] [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface IManager { [DispId(1)] void Display(ADODB.Recordset recordSet); [DispId(2)] void Close(); } [Guid("B9BB5B84-8FBD-4095-B846-EC072163ECD3")] [ClassInterface(ClassInterfaceType.None)] [ProgId("This.Is.GonnaBe.MyClass")] public class Manager : IManager { public void Display(ADODB.Recordset recordset) { // do stuff } public void Close() { // do stuff } } 
+1
source

All Articles