tags:

views:

60

answers:

2

I noticed that MIDL.exe only generates header file (*_h.h) and GUID file (*_i.c) for C/C++. Which facilitates creating COM in C/C++.

What if I want to create COM in VB or some other language? IMO, I must define the interface in MIDL language first, and then compile it with MIDL.exe. So how could other languages utilize the output of MIDL.exe?

Many thanks.

A: 

If you want to write a COM component in VB.NET, you won't define the interface in MIDL. Instead, you'll write a managed interface, and a class that implements it, in the usual .NET way. Then you make the class and interface ComVisible and arrange for your project to create the Com Callable Wrappers for the resulting assembly.

Keep in mind that what you create in this way will have a dependency on the .NET Framework.

Kate Gregory
Thanks Kate. I am not familiar with VB. But it seems VB saves a lot of our effort.
smwikipedia
+3  A: 

Runtime environments like VB6 and .NET treat COM as a first-class citizen and do not require the plumbing that midl.exe provides. A VB6 class is automatically a COM coclass that implements IDispatch. .NET has attributes like [ComVisible]. Their runtime environments implements the glue needed.

No such glue in C++, you have to write it yourself. Or leverage a class library like ATL. It does however allow moving beyond the confines of oleauto, like implementing interfaces that derive from IUnknown and creating custom marshallers.

Hans Passant
Thanks Hans. 8^D
smwikipedia