Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating a COM visible assembly from managed c++ (C++/CLI)

I need to develop some classes that should be callable from VB6 with Managed C++ (C++/CLI).

I've developed first a sample in C# and I can use the assembly through COM without problems just using the setting "Register for COM interop" and "Make assembly COM visible" (and using the attribute [ClassInterface(ClassInterfaceType.AutoDual)] to make methods available at VB6.

After that I tried to translate the sample to C++/CLI without success. I've created the same class with the [ClassInterface(ClassInterfaceType.AutoDual)] attribute. I've set the "Embedded IDL" setting to specify the output TLB but the TLB is not generated automatically. If I use the tlbexp util over the generated DLL I get a tlb that can be imported at VB6 but when I try to create an instance I get an "ActiveX compoennt can't create object (429)"

What more do I need to do with the project to let it run?

Thanks in advance.

like image 444
Ignacio Soler Garcia Avatar asked Oct 29 '10 15:10

Ignacio Soler Garcia


1 Answers

Not much to go on but you never mentioned registering the assembly. The C++ IDE doesn't have the "Register for COM interop" option. From the Visual Studio Command Prompt, run Regasm.exe on the assembly to get it registered. You need the /codebase option if you don't put the assembly in the GAC. And the /tlb option generates the type library, making tlbexp.exe unnecessary.

like image 154
Hans Passant Avatar answered Sep 19 '22 09:09

Hans Passant