从VB 6代码调用受管DLL的问题 [英] Problem with calling a managed DLL from VB 6 code
问题描述
我已经使用Visual Studio 2008转换向导将VB6代码移植到VB.Net。已移植的代码正确编译。
I have ported VB6 code to VB.Net using the Visual Studio 2008 conversion wizard. The ported code compiles correctly.
我已经检查编译器选项注册项目属性上的COM互操作。在构建项目时,我得到DLL和TLB文件。
I have checkd the compiler option to register for COM interop on project properties. On building the project I get the DLL and TLB file.
我已使用以下命令注册程序集
I have registered the assembly using following command
regasm myLib.DLL /tlb:myLib.tlb
我已使用
gacutil /i myLib.DLL
现在,正在使用DLL的VB代码...
Now, the VB code that was consuming the DLL ...
Dim myObject
Set myObject= CreateObject("myLib.MyObject")
引发错误 -
运行时错误429,ActiveX components无法创建对象。
Runtime Error 429, ActiveX componenet cant create object.
$ b
推荐答案
需要检查的一件事情是什么?
$ b
-
One thing to check that has caught me out in the past:-
如果你的.NET中的构造函数抛出一个错误(无论是否被处理),并且正在创建你的对象在VB6中使用 CreateObject
,您会收到一个运行时错误429,ActiveX components不能创建对象。
If your constructor in the .NET side throws an error (whether it is handled or not) and you are creating your object in VB6 using CreateObject
, you receive a Runtime Error 429, ActiveX componenet cant create object.
在开发期间,您最好添加对您的托管项目的引用并使用:
During development you are better off adding a reference to your managed project and using:
Dim myObject
Set myObject = New myLib.MyObject
这样你至少可以看到错误已在被管理端抛出。
That way you can at least see that an error has been thrown on the managed side.
这篇关于从VB 6代码调用受管DLL的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!