views:

115

answers:

3

I am considering using COM interfaces within an embedded (non-Windows) system that has a limited C++ compiler, and I am looking for an open-source COM implementation using simple C++, in particular with little or no use of templates and without use of exceptions (yes I know COM doesn't use exceptions but an implementation could use them internally).

At this point I'm mainly looking for C++ definitions of all the core COM types i.e. IUnknown, IDispatch, VARIANT etc. plus some helper classes for smart pointers, BSTRs etc. Some level of support for implementing QueryInterface and IDispatch might be nice but I can also do that myself. I'd like to find an ITypeInfo implementation, and an embedded implementation of DCOM would be attractive.

I know I could use Microsoft's source supplied with Visual Studio but I would rather avoid it because of the complexity of pulling in a lot of definitions that I don't need, plus I want to avoid any possible legal issues with using it on a non-Windows platform. I'm also thoroughly familiar with ATL and I can't use such a heavily templated approach due to compiler limitations. I have a lot of experience with COM and DCOM so I could write all of the definitions and helper classes myself, and I could even write my own DCOM system if needed. But I'd rather use an existing open-source implementation if there is one. Do you have any recommendations?

+1  A: 

The closest Open Source implementation I am aware of is Mozilla's XPCOM (it's not exactly the same as Microsoft's COM, but is quite similar). But I am not sure if it's still possible to build it standalone as the instructions provided are quite outdated now.

cmeerw
+1  A: 

I would suggest looking at Wine. Source code is in C, not C++, thus avoiding any and all issues with full C++ support, C++ templates, etc. Wine also has implementations for many (most?) of the standard interfaces.

For example, source code to LoadTypeLib (which returns an ITypeInfo implementation) is in dlls/oleaut32/typelib.c:383. ITypeInfo::AddressOfMember is at typelib.c:6742 (in ITypeInfo_fnAddressOfMember).

(It is somewhat odd to see COM implemented in C, but COM defines a binary standard precisely for this reason, so that COM components can be implemented in any language without placing restrictions on the consuming language...)

jonp
+2  A: 

A few years ago I was considering starting a FOSS implementation of COM/DCOM, but didn't get anywhere, mainly because I didn't think that would be interesting to anyone in the open source community. There is the proprietary implementation by Software AG (called EntireX DCOM), which I assume would not be interesting to you.

As for open source projects, other than Samba and Wine implementations and XPCOM in Mozilla, there is OpenCOM. They have posted their code on SourceForge.

ajanicij