How to call a .Net COM+ object from C++ functions library?

Topics: Building and extending application blocks, General discussion
Mar 30, 2011 at 4:48 PM
Edited Mar 30, 2011 at 4:49 PM

I've not found some example that really works. I need to create an interaction system for MetaTrader. It's better to use modern technologies like WCF or somehting else using C#, but MetaTrader doesn't support COM or just OOP at all. So I need some gateway component that must be functions library with non-object interface. Surely, it requires usage of C++. But I'm not succeeded to find over the Web some example how to call from a C++ functions library a C# COM+ DLL. All the examples I could find use component C++ assemblies that are not supported by MetaTrader. So, I can't use namespace, etc. in C++. I wrote a COM+ server application that is easy to call from C# by the following lines

            object c2 = Activator.CreateInstance(Type.GetTypeFromProgID("Imutome.COMPlusCache.Cache"));
            c2.GetType().InvokeMember("OnTransfer", BindingFlags.InvokeMethod, null, c2, null);

But when I'm trying to write in C++ something like this

	CLSIDFromProgID(OLESTR("Imutome.COMPlusCache.Cache"), &rclsid);
	CoInitialize(NULL);
	HRESULT	hres = CoCreateInstance(rclsid, NULL, CLSCTX_ALL, IID_IDispatch, (void **)&ppv);

I get just zeros in ppv and "0x80040154 Class not registered" in hres. Here http://support.microsoft.com/kb/962555/en-us there's no useful information. I'm not sure what interface is required but I've not succeeded to find what can I replace it with. Although in C# everything works. Here's the screenshot of Component Services http://s54.radikal.ru/i145/1103/54/3a8c18ecb5de.gif Tell me please what do I need to change to make C++ succesfully create a COM+ object instance.

Mar 31, 2011 at 12:43 AM

Sorry but you would need to post this in other forums as this discussion board is for Enterprise Library-related topics.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com