using a VB.NET dll in VB6
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: using a VB.NET dll in VB6

  1. #1
    Join Date
    Dec 2012
    Posts
    4

    using a VB.NET dll in VB6

    Hello,

    I am trying to create a DLL in VB.NET (2012) which I will then use in several existing VB6 applications.

    I have already built the DLL but I cannot get VB6 to use it! I created a DLL registered for COM interop, run regasm and pretty much everything else I found on the net, and I ended up with "myClass.dll" and "myClass.tlb".

    Going back to VB6 now, I added the tlb to the references (the dll cannot be added it seems). When I run my application, at the point where I try to create a new instance of my main dll class, I get a crash instead... "ActiveX component can't create object"

    I remember that this is related to dll's that are not registered, but when I try to register the tlb with regsvr32 I get "myClass.tlb is not an executable file and no registration helper is registered for this file type." and when I try to register the dll I get "myClass.dll was loaded, but the DllRegisterServer entry point was not found. This file can not be registered.".

    What am I missing? is it correct that I need both files (dll & tlb) and that I need to reference the tlb and register the dll?

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,098

    Re: using a VB.NET dll in VB6

    "myClass.dll was loaded, but the DllRegisterServer entry point was not found. This file can not be registered."

    This means that your dll is not properly set up. Show the code for this DLL and we might be able to find the problem. It might also be that your dealing with a 32 bit versus 64 bit system.

    What version of Windows do you have? Is it 32 bit or 64 bit?

  3. #3
    Join Date
    Dec 2012
    Posts
    4

    Re: using a VB.NET dll in VB6

    Thank you for your response!

    I am coding the dll in VB.NET under windows 7 64bit and the executable is in VB6 winXP 32bit, but I made sure that I targeted "any CPU" in the dll compile properties, so this should not be a problem.

    I am attaching the code for "myClass":

    Code:
    <ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _
    Public Class ComClass1
    
    #Region "COM GUIDs"
        ' These  GUIDs provide the COM identity for this class 
        ' and its COM interfaces. If you change them, existing 
        ' clients will no longer be able to access the class.
        Public Const ClassId As String = "74d3a0f0-3f5b-4d48-9dc4-4df224043e1e"
        Public Const InterfaceId As String = "ed7e662f-bd37-44f3-b9eb-11ab1f262358"
        Public Const EventsId As String = "04c9bb8b-0db3-4578-adcb-51d461d28d99"
    #End Region
    
        ' A creatable COM class must have a Public Sub New() 
        ' with no parameters, otherwise, the class will not be 
        ' registered in the COM registry and cannot be created 
        ' via CreateObject.
        Public Sub New()
            MyBase.New()
        End Sub
    
        Public Sub hi()
            Dim frm1 As Form1 = New Form1
            frm1.Show()
        End Sub
    
    End Class

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,098

  5. #5
    Join Date
    Dec 2012
    Posts
    4

    Re: using a VB.NET dll in VB6

    Thank you once again.

    I have read through these articles but none of them referred to the "entry point not found" issue. Are you sure that this is related to 32bit/64bit issues? Again, I have compiled for "all CPUs" and even tried 32bit only. Shouldn't this resolve the problem if it was bit-related?

  6. #6
    Join Date
    Dec 2012
    Posts
    4

    Re: using a VB.NET dll in VB6

    I found the solution!

    I initially thought that you need to do the "regasm" in the development machine and then transfer the dll to the target machine and register with "regsvr32" there.

    This is wrong! Instead, when you create a DLL in VB.NET then you need to register it directly in the target machine using "regasm.exe" (which is in the .NET redistributable) and NOT with "regsvr32.exe".

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center