Search code examples
.netcomvb6com-interopvb6-migration

Problem with calling a managed DLL from VB 6 code


I have ported VB6 code to VB.Net using the Visual Studio 2008 conversion wizard. The ported code compiles correctly.

I have checkd the compiler option to register for COM interop on project properties. On building the project I get the DLL and TLB file.

I have registered the assembly using following command

regasm myLib.DLL /tlb:myLib.tlb

After that I have GACed the assembly using

gacutil /i myLib.DLL

Now, the VB code that was consuming the DLL ...

 Dim myObject
    Set myObject= CreateObject("myLib.MyObject")

..throws an error -

Runtime Error 429, ActiveX componenet cant create object.

WHat do I need to do to get this working correctly?


Solution

  • One thing to check that has caught me out in the past:-

    If your constructor in the .NET side throws an error (whether it is handled or not) and you are creating your object in VB6 using CreateObject, you receive a Runtime Error 429, ActiveX componenet cant create object.

    During development you are better off adding a reference to your managed project and using:

    Dim myObject
    Set myObject = New myLib.MyObject
    

    That way you can at least see that an error has been thrown on the managed side.