[Mono-dev] Creating Managed COM objects from C++ (on linux).
Andreas Färber
andreas.faerber at web.de
Sun Dec 21 10:31:21 EST 2008
Hi,
Am 19.12.2008 um 22:27 schrieb Tom Hindle:
> I had to convert from a MonoObject to a COM interface pointer.
> The only way I could work out how to do this was by using some
> internal mono functions. (removing static from mono src files ect.)
>
>> comClassInstance = mono_object_new (m_domain, comClass);
>>
>> if (comClassInstance == NULL)
>> {
>> fprintf(stderr, "Failed to create instance of %s.%s from assembly
>> %s\n", classNamespace.c_str(), className.c_str(),
>> assemblyName.c_str());
>> return 1;
>> }
>>
>> ////
>> // Get object callable from C++
>> ////
>>
>> mono_init_com_types(); // Internal mono function
>>
>> void *pCCW =
>> (void
>> *)ves_icall_System_Runtime_InteropServices_Marshal_GetIUnknownForObjectInternal
>> (comClassInstance); // Internal mono function
>>
>> cominterop_ccw_queryinterface(pCCW,(guint8*)&riid,
>> (void**)ppvObject); // Internal mono function
>
> I think I could replace
> ves_icall_System_Runtime_InteropServices_Marshal_GetIUnknownForObjectInternal
> with mono_lookup_internal_calls
> but I don't know how to get around the need to call
> mono_init_com_types() and cominterop_ccw_queryinterface().
Regarding the icall, you could just obtain the corresponding
MonoMethod* and execute it via mono_runtime_invoke.
For the other two, just check where they are called normally.
HTH,
Andreas
More information about the Mono-devel-list
mailing list