1
votes

I have a VB6 Standard EXE with no embedded type library. I'd like to generate an interop assembly from that executable and reference it from a .NET project. This should allow me to instantiate COM classes defined in the executable from .NET.

Since I don't have a type library, I tried creating the IDL from scratch, used MIDL to generate a typelib, and generated an interop assembly from the typelib. I can reference the interop assembly from my .NET project, but still can't instantiate any COM classes. I believe my interop assembly doesn't know about the EXE and therefore can't actually execute the code I call.

I've already successfully instantiated COM classes defined in VB6 ActiveX DLLs from .NET, where the interop assemblies know the ClassID of the corresponding COM DLLs containing the implementation.

In the IDL I'm creating from scratch, what should I be using as the UUID for the library definition? Should this refer to the EXE somehow?

[
    uuid(WHATUUID-SHOU-LDII-NCLU-DEHEREXXXXXX),
    version(1.0),
    helpstring("for TLB on EXE")
]
library MyExe { ... }

These questions are close, but I'm still stuck. Is what I'm trying to do possible? I'd rather avoid late-binding. Thanks for any help.

1

1 Answers

2
votes

The interop library is not supposed to know about the EXE, that's how COM works. It is the CLSID key that tells how the server is supposed to be started. InProcServer32 vs LocalServer32.

There are a million things that can go wrong when you write your own IDL. Guessing the proper guids for the interfaces and coclasses is non-trivial if you don't have a type library. If you get it wrong then you can't create the COM class. I'm pretty sure that the type library is embedded in vb6 ActiveX .exes, there's no option that I remember to not embed it. To verify, use Visual Studio's File + Open + File and select the .exe. You'll get the embedded resources, you're happy if you see TYPELIB. Open the node, right-click ID 1 and use Export to export it to a .tlb file.