[英]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'我有 ActiveX VB6 DLL(无法访问其源代码),并且想调用方法“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
无法在 DLL 中找到名为“GetUnitInfo”的入口点
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)
(来自 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...我已经尝试清理解决方案,关闭项目选项中的清单,创建新的清单文件,但它并没有帮助我......
Found solution, mb someone else will find useful, (this worked in my case):找到解决方案,其他人会觉得有用,(这在我的情况下有效):
Create .Net wrapper of VB6 ActiveX dll创建 VB6 ActiveX dll 的 .Net 包装器
1.1 Run CMD as Administrator 1.1 以管理员身份运行CMD
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.2 移动到 .NET SDK 文件夹 -
cd C:\Program Files\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\
(在我的例子中)。
1.3 Run - TlbImp.exe C:\path_to_old.dll /out: new.dll
1.3 运行 -
TlbImp.exe C:\path_to_old.dll /out: new.dll
Register ActiveX dll注册 ActiveX dll
2.1 Run CMD as Administrator 2.1 以管理员身份运行CMD
2.2 Run - regsvr32.exe C:\path_to_old.dll
2.2 运行
regsvr32.exe C:\path_to_old.dll
I used to add "new.dll" reference before registering "old.dll", and was getting the following exception我曾经在注册“old.dll”之前添加“new.dll”引用,并得到以下异常
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))
由于以下错误,检索具有 CLSID {F2D4F4E5-EEA1-46FF-A83B-A270C92DAE4B} 的组件的 COM 类工厂失败:80040154 未注册类(HRESULT 异常:0x80040154 (REGDB_E_CLASSNOTREG))
Cleaning solution, removing reference and following steps 2,3 - helped清洁溶液,删除参考并遵循步骤 2,3 - 帮助
You may also find useful this articles您可能还会发现这篇文章很有用
C-Sharp-and-activex-dll C-Sharp-and-activex-dll
Error adding reference to dll: Solution tlbimp.exe添加对 dll 的引用时出错:解决方案 tlbimp.exe
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.