问题
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...
回答1:
Found solution, mb someone else will find usefull, (this worked in my case):
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.dllRegister ActiveX dll
2.1 Run CMD as Administrator
2.2 Run -
regsvr32.exe C:\path_to_old.dllAdd 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
来源:https://stackoverflow.com/questions/52540578/how-to-use-method-from-vb6-dll-in-net