How to use method from VB6 dll in .NET?

5

I have ActiveX VB6 DLL (have no access to its sources), and want to call method 'GetUnitInfo'

I use to import it like:

[DllImport(@"C:\Users\R\Documents\lab.dll")]
public static extern long GetUnitInfo(String strRequest, String strInfo, String strName);

But I get an exception:

Unable to find an entry point named 'GetUnitInfo' in DLL

Also I have tryied to load it:

Assembly myAssembly ;
myAssembly = Assembly.LoadFile("C:\\Users\\R\\Documents\\lab.dll");

but getting an exception

The module was expected to contain an assembly manifest. (Exception from HRESULT: 0x80131018)

I have tryied to clean solution, to turn off manifest in project options, to create new manifest file, but it did not helped me...

c#
vb.net
vb6
dllimport
asked on Stack Overflow Sep 27, 2018 by Little Fox • edited Sep 29, 2018 by Little Fox

1 Answer

7

Found solution, mb someone else will find usefull, (this worked in my case):

  1. Create .Net wrapper of VB6 ActiveX dll

    1.1 Run CMD as Administrator

    1.2 Move to .NET SDK folder - cd C:\Program Files\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\ (in my case).

    1.3 Run - TlbImp.exe C:\path_to_old.dll \out: new.dll

  2. Register ActiveX dll

    2.1 Run CMD as Administrator

    2.2 Run - regsvr32.exe C:\path_to_old.dll

  3. Add Reference to converted dll ("new.dll") in c# project

I used to add "new.dll" reference before registering "old.dll", and was getting following exception

Retrieving the COM class factory for component with CLSID {F2D4F4E5-EEA1-46FF-A83B-A270C92DAE4B} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))

Cleaning solution, removing reference and following steps 2,3 - helped

You may also find useful this articles

C-Sharp-and-activex-dll

Error adding reference to dll: Solution tlbimp.exe

answered on Stack Overflow Sep 27, 2018 by Little Fox • edited Sep 27, 2018 by Visual Vincent

User contributions licensed under CC BY-SA 3.0