Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to use ActiveX VB6 dll in c# .net application to Test COM, but it giving me run time error that class is not registered.

i have tried registering in both 32bit and 64 bit application and also tried targeting the same

What I have tried:

I have created VB6 Project of ActiveX dll type added two function
VB
 Public Function Name(aName As String)
MsgBox ("Your Name is " & aName)
End Function

Public Function TestName(aName As String) As String
TestName = " Hello  " & aName
End Function

Created DLL from same Project.

Then created Wrapper using below command .

C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools>TlbImp.exe C:\Test\TestActiveX\Project1.dll /out: C:\Test\TestActiveX\out\Project1.dll

If i am performing only above operation then i am not getting Project1.dll under COM section but then i am registering dll using below code

C:\WINDOWS\system32>regsvr32 C:\Test\TestActiveX\Project1.dll

then only i am getting dll under COM section inside VisuaL studio Add Reference Dialog

i tried adding reference from C:\Test\TestActiveX\out\Project1.dll folder also but every time i am getting runtime error as below.

System.Runtime.InteropServices.COMException: 'Retrieving the COM class factory for component with CLSID {ID} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).'
C#
public string ReturnFromCOM()
    {
        TestClass testClass = new TestClass();
        return testClass.TestName(" Hello ");
    }

i am not able to get it done, don't know what is missing in this steps. My Windows OS : 64 bit Windows 10 Framework 4.6.1 as well as 4.8.1 but created console application with Framework 4.6.1

i tried even changing project target to x64/x86/anyCPU but it's not working at all.
Posted
Updated 27-Dec-19 5:15am
Comments
F-ES Sitecore 27-Dec-19 8:58am    
You don't need tlbimp. Simply build the dll, register it with regsvr32 then add the reference via the COM tab in Add Reference. COM doesn't work like .net, it is registry-based rather than file-based so you don't reference the dll directly, it is location agnostic but has to stay wherever you have registered it.

First, you don't need TlbImp at all.

Your VB6 .DLL needs to be registered before you can use it. To do that, you launch a CMD prompt and navigate to where your VB6 .DLL is. You then run REGSVR32 filename.dll to register your .DLL. Close the CMD window.

Once that's done, in your C# project, in Solution Explorer, right-click References, then pick Add Reference. Switch the COM tab and you can find your .DLL in the list. Check the box next to it and click OK.

Once the reference is added, you can use the classes and functions in the .DLL in your C# code.

To explore the .DLL, you can open the Object Browser window with Ctrl-W, J.

If adding the reference doesn't work or comes back with an error, chances are your VB6 .DLL needs some dependency installed in order for it to work. We can't tell you what that is. We know absolutely nothing about your .DLL.
 
Share this answer
 
v2
Comments
Viken Patel 28-Dec-19 1:50am    
yes thanks this worked for me. all i used one function to test but can you let me know what if there is other dependency, then how it can be resolved ?
RickZeeland 28-Dec-19 5:05am    
You can try to use Dependency Walker to see if any dependent dll's are missing, the tool can be a bit confusing though for beginners :)
Dave Kreskowiak 28-Dec-19 10:20am    
I can't tell you anything about what your DLL might be dependent on. I know nothing about it, what it does, how it was written, ... nothing.

Like Rick said, Google for "Dependency Walker" and use that to see what your .DLL is dependent on.
Try running VS as Administrator (if you haven't done that already), otherwise take a look at the answers here: VB6 DLL Imported in C# .net project - Class not registered - Stack Overflow[^]
 
Share this answer
 
Comments
Viken Patel 27-Dec-19 7:58am    
tried this application also codeproject.com/Articles/154144/Using-Unmanaged-VB6-Code-in-NET , getting same error , also tried changing target x86/x64/Any CPU for this application also but same result.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900