Registering a .NET dll for use in VB6 application

10,234

Solution 1

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

Solution 2

The reason this is happening is because you have not assigned a GUID to your classes. Your class in .NET should be decorated like this:

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

This way your class will get compiled with the same GUID attribute every time you run regasm against it. If you do not include this attribute, regasm will auto-assign a different GUID every time.

To be completely safe, your class must inherit from an 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
    }
}
Share:
10,234
La La La
Author by

La La La

Updated on June 24, 2022

Comments

  • La La La
    La La La almost 2 years

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

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

    I need to run it on a computer which does not have VS2008, so I tried to register this DLL like so:

    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 file specified.

    Can anybody tell me what I'm doing wrong?

  • La La La
    La La La almost 13 years
    I'm running regasm from the path of my dll.
  • Dabblernl
    Dabblernl almost 13 years
    @ La La La: Did you try my suggestion?
  • La La La
    La La La almost 13 years
    BTW, I create the instance with "CreateObject".
  • AngryHacker
    AngryHacker almost 13 years
    With CreateObject, I don't know - don't really have experience with that. But if you choose to do early binding, the process is this: when you compile your main app against the lib, it uses the existing lib GUID to access it. On other PCs, you are doing a regasm, which generates new GUIDs, but you do not compile your main app, do you. Try this experiment. Compile your main app. Go to the registry and remove any GUIDs associated with your lib, redo regasm and then kick off the main app (without recompile). I am guessing it won't work.
  • AngryHacker
    AngryHacker almost 13 years
    IIRC, with CreateObject, Interop/COM uses a different interface to access the lib, that is why you might be facing challenges. But I don't know enough about it.