0

I have created VB6 Project of ActiveX dll type added two function

 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)).'

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.

Viken Patel
  • 77
  • 1
  • 5
  • When you compile in VB6 it registers the DLL automatically for you at that time. Also when you choose that VB6 DLL as a reference in Visual Studio (C#) it will do all the import steps for you automatically. Possibly some of the extra manual work you are doing is introducing a problem. – StayOnTarget Jan 02 '20 at 12:31

1 Answers1

0

Check if your VB6 TestClass instancing is set to "MultiUse"

enter image description here

Also try referencing your VB6 dll from another VB6 project and try the same code (translated to VB6) as from C# function ReturnFromCOM.

Smith
  • 710
  • 1
  • 7
  • 11
  • it's able to call from other VB6 Project – Viken Patel Dec 27 '19 at 04:40
  • Many solutions related to 0x80040154 error (Google and this site) are about platform target setting should be x86 (not Any CPU). You said that you tried that, but there may be some useful tips at https://stackoverflow.com/questions/4663994/system-runtime-interopservices-comexception-0x80040154 https://stackoverflow.com/questions/1036856/retrieving-the-com-class-factory-for-component-with-clsid-xxxx-failed-due-to-t https://stackoverflow.com/questions/11845428/com-class-factory-error-80040154 – Smith Dec 27 '19 at 11:46
  • tried this application also https://www.codeproject.com/Articles/154144/Using-Unmanaged-VB6-Code-in-NET , getting same error , also tried changing target for this application also but same result. – Viken Patel Dec 27 '19 at 12:54
  • it has resolved by this link there was no need to use tlbimp.exe for wrapping in .net application https://www.codeproject.com/Questions/5255105/How-to-use-vb6-DLL-function-in-Csharp-NET-using-4 – Viken Patel Dec 28 '19 at 06:51