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

查看:91
本文介绍了如何从.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:\Users\R\Documents\lab.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...

推荐答案

找到了解决方案,mb其他人会发现有用,(在我情况):

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 Files\Microsoft SDKs\Windows\ \v10.0A\bin\NETFX 4.6.1工具\ (在我的情况下)。

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运行- TlbImp.exe
C:\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

我曾经添加了 new .dll引用,然后注册以下异常

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


为具有CLSID {F2D4F4E5的组件检索COM类工厂-EEA1-46FF-A83B-A270C92DAE4B}由于以下错误而失败: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天全站免登陆