tags:

views:

64

answers:

3

I am having problems when using a VB.NET dll in a VB6 program. I have already created my dll with the GuidAttribute, used the RegAsm to create a tlb and added it to the references of my VB6 program. The problem is when I try to create the object using CreateObject function, however the following error shows up "ActiveX componnent can't create object."

I don't know if I am missing any declaration on VB.NET to use it as a dll or if I am not using the CreateObject function properly.

Thanks for the help.

João Pedro

A: 

you have to make sure your compenent is properly registered for com interop.. in the projects properties tab there is a checkbox option for enabling this, you are acutally on the right path with creating a type lib that you can reference in vb6, you can simple add reference to it like any other com compenent. however actually register it rather than creating a tlb file.

When you register an assembly for use by COM, Regasm.exe adds entries to the registry on the local computer. More specifically, it creates version-dependent registry keys that allow multiple versions of the same assembly to run side by side on a computer. The first time an assembly is registered, one top-level key is created for the assembly and a unique subkey is created for the specific version. Each time you register a new version of the assembly, Regasm.exe creates a subkey for the new version.

After registering an assembly using Regasm.exe, you can install it in the global assembly cache so that it can be activated from any COM client. If the assembly is only going to be activated by a single application, you can place it in that application's directory.

if you are interested in what the tool generates for the registry use

regasm {Path to your Assembly}.dll /regfile:myTest.reg

almog.ori
A: 

Hard to say with the info you've provided, but it sounds like you didn't make the assembly findable. From MSDN:

Under the HKCR\CLSID{0000…0000} key, the default value is set to the ProgID of the class, and two new named values, Class and Assembly, are added. The runtime reads the Assembly value from the registry and passes it on to the runtime assembly resolver. The assembly resolver attempts to locate the assembly, based on assembly information such as the name and version number. For the assembly resolver to locate an assembly, the assembly has to be in one of the following locations:

The global assembly cache (must be a strong-named assembly).

In the application directory. Assemblies loaded from the application path are only accessible from that application.

Along an file path specified with the /codebase option to Regasm.exe.

David Gladfelter
+1  A: 

A complete article about Calling .Net Classes from Visual Basic 6: http://www.devsource.com/c/a/Using-VS/Calling-Net-Classes-from-Visual-Basic-6/

Creating a COM DLL with VS 2005: A walk through: http://www.codeproject.com/KB/COM/VS2005ComDllWalkThru.aspx

mangokun