Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use method from VB6 dll in .NET?

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

like image 294
Little Fox Avatar asked Sep 27 '18 15:09

Little Fox


People also ask

Can I use VB DLL in C#?

Compile the VB Project into the DLL and then import a reference to it. You can create a solution that contains VB projects and C# projects. you just can't have C# and VB.NET class files in the same project.

What is DLL in vb6?

In VB, you create a Dynamic Link Library (DDL) by selecting ActiveX DLL from the New Project dialog box. This tip highlights the various uses and benefits of using DLLs. A Dynamic Link Library (DDL) is a file that. contains compiled code.


1 Answers

Found solution, mb someone else will find useful, (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

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

I used to add "new.dll" reference before registering "old.dll", and was getting the 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

like image 70
Little Fox Avatar answered Sep 25 '22 14:09

Little Fox