开发者

How to make a COM in language other than C/C++?

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 i开发者_运维技巧nterface in MIDL language first, and then compile it with MIDL.exe. So how could other languages utilize the output of MIDL.exe?

Many thanks.


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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜