如何在 .NET 中使用来自 VB6 dll 的方法? [英] How to use method from VB6 dll in .NET?

查看:28
本文介绍了如何在 .NET 中使用来自 VB6 dll 的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 ActiveX VB6 DLL(无法访问其源代码),并且想要调用方法GetUnitInfo"

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:UsersRDocumentslab.dll")]
public static extern long GetUnitInfo(String strRequest, String strInfo, String strName);

但我得到一个例外:

无法在 DLL 中找到名为GetUnitInfo"的入口点

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

我也尝试过加载它:

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

但遇到异常

该模块应包含程序集清单.(HRESULT 异常:0x80131018)

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

推荐答案

找到解决方案,别人会觉得有用,(这在我的情况下有效):

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

  1. 创建 VB6 ActiveX dll 的 .Net 包装器

  1. Create .Net wrapper of VB6 ActiveX dll

1.1 以管理员身份运行 CMD

1.1 Run CMD as Administrator

1.2 移动到 .NET SDK 文件夹 - cd C:Program FilesMicrosoft SDKsWindowsv10.0AinNETFX 4.6.1 Tools(在我的例子中).

1.2 Move to .NET SDK folder - cd C:Program FilesMicrosoft SDKsWindowsv10.0AinNETFX 4.6.1 Tools (in my case).

1.3 运行 - TlbImp.exeC:path_to_old.dll out: new.dll

注册 ActiveX dll

Register ActiveX dll

2.1 以管理员身份运行 CMD

2.1 Run CMD as Administrator

2.2 运行 - regsvr32.exe C:path_to_old.dll

在 c# 项目中添加对转换后的 dll(new.dll")的引用

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

我曾经在注册old.dll"之前添加new.dll"引用,并得到以下异常

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

检索具有 CLSID {F2D4F4E5-EEA1-46FF-A83B-A270C92DAE4B} 的组件的 COM 类工厂失败,原因是以下错误:80040154 未注册类(HRESULT 异常:0x80040154 (REGDB_E_CLASSNOTREG))

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

清洁解决方案,删除参考并按照步骤 2,3 - 帮助

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

您可能还会发现这篇文章很有用

You may also find useful this articles

C-Sharp-and-activex-dll

添加对 dll 的引用时出错:解决方案 tlbimp.exe

这篇关于如何在 .NET 中使用来自 VB6 dll 的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆