Viken Patel

Viken Patel

  • 2k
  • 72
  • 1.5k

Use VB6 dll in c#

Dec 27 2019 6:30 AM
I have created VB6 Project of ActiveX dll type added two function
  1. Public Function Name(aName As String)  
  2. MsgBox ("Your Name is " & aName)  
  3. End Function  
  4. Public Function TestName(aName As StringAs String  
  5. TestName = " Hello " & aName  
  6. 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)).'
  1. public string ReturnFromCOM()  
  2. {  
  3. TestClass testClass = new TestClass();  
  4. return testClass.TestName(" Hello ");  
  5. }  
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.

Answers (2)