[Mono-dev] Creating Managed COM objects from C++ (on linux).

Bill Holmes billholmes54 at gmail.com
Fri Dec 19 17:07:53 EST 2008

We have dealt with this by registering a global class factory method
(that is implemented in C#) with native C++ code.

I assume you are hosting the mono runtime?

Take a look at the poor code example below and see if that gives you the idea.


/* C++ code */
void cppMain ()
	// Init Mono Runtme
	// Call managed InitManagedCOMFactory
	IUnknown* pObj;
	ManagedCOMFactoryCreateObject (CLSID_MyObj, &pObj);
	IFoo* pFoo;
	pObj->QueryInterface (IID_IFoo, (void**)&pFoo);


uint (*ManagedCOMFactoryCreateObject) (GUID*, IUnknown**);

void RegsterManagedCOMFactoryCreateObject (void* ptr)
	ManagedCOMFactoryCreateObject = ptr;	

/* C# code */

void InitManagedCOMFactory ()
	RegsterManagedCOMFactoryCreateObject (ManagedCOMFactoryCreateObject);	

uint ManagedCOMFactoryCreateObject (guid g, [MarshalAs (IUnknown)] out
object retObj)
	if (g == myGuid)
		retObj = new MyObject ();

More information about the Mono-devel-list mailing list