[Mono-dev] Creating Managed COM objects from C++ (on linux).
Tom Hindle
tom_hindle at sil.org
Fri Dec 19 18:23:19 EST 2008
On Fri, 2008-12-19 at 17:07 -0500, Bill Holmes wrote:
> 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?
Yes.
>
> Take a look at the poor code example below and see if that gives you the idea.
Thanks for the idea!
I think I would still prefer being able to do it via the mono c API and
so not having an assembly coupled with my COM object, but a least I now
have a solution if I can't do that.
I guess I can use reflection, to search in the assembly for the class
associated with the CLSID, in the implementation of
ManagedCOMFactoryCreateObject to make it generic.
Thanks,
Tom
>
> -bill
>
> /* 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