开发者

Problem with calling a managed DLL from VB 6 code

I have ported VB6 code to VB.Net using the Visual Studio 2008 conversion wizard. The ported code compiles correctly.

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

After that I have GACed the assembly using

gacutil /i myLib.DLL

Now, the VB code that was consuming the DLL ...

 Dim myObject
    Set 开发者_运维技巧myObject= CreateObject("myLib.MyObject")

..throws an error -

Runtime Error 429, ActiveX componenet cant create object.

WHat do I need to do to get this working correctly?


One thing to check that has caught me out in the past:-

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.


  1. Starting with the basics, did you set the objects you wished to expose to VB6 as ComVisible? If I recall correctly, Visual Studio 2008 be default has ComVisible(false) at the Assembly level, where as in earlier Visual Studio editions it used to default to True.

EDIT #1:

  1. Are you using a deeply nested namespace or complex assembly name? I've found that using the mycompany.myproduct.subcomponent style naming convention for assembly and namespace names messes with the type exporter. It uses the namespace to create the left-hand-side of the programatic ID that you need in VB6.

  2. What message is output when you run RegAsm? If it cannot find any types to register it usually tells you.

  3. Inspect the TypeLib and see if the types you expect to see are in there. You can refrence the tlb directly from VB6 and hit F2 to view the TypeLib. Of you can use OLE View that come with Visual Studio 6.

  4. Have you tried using the /codebase option when registering your component to see if it behaves differently? I almost always use codebase registration, since that is similar to how regular COM registration works anyway.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜