Difference between revisions of "ManagedComBridge"

From LSDevLinux
Jump to: navigation, search
m (Categorize)
 
Line 40: Line 40:
 
This should write a .tlh file in the Output Directory.
 
This should write a .tlh file in the Output Directory.
 
* modify the .tlh file so that it works with libcom ** TODO Write better instructions for this step **
 
* modify the .tlh file so that it works with libcom ** TODO Write better instructions for this step **
 +
 +
[[Category:COM]]
 +
[[Category:.NET]]

Latest revision as of 12:11, 21 January 2010

This documentation is a work in progress.

ManagedComBridge is a library the implements a special COM object, that can be used with libcom to Create Managed mono COM object in a Native running application.


Some example lines from the components.map file.


# managed-com-bridge: MyDotNetClass
0490e147-f2d2-4909-a4b8-3533d2f264d0 libManagedComBridge.so TestComObject.dll TestComObject.MyDotNetClass

# managed-com-bridge: IMyDotNetInterface
03ad5d2d-2afd-439f-8713-a4ec0705b4d9 libManagedComBridge.so

This example shows a Managed declared interface IMyDotNetInterface and a Managed defined interface MyDotNetClass

And here is some example C++ code which shows it being used.

TestComObject::IMyDotNetInterface *ptrMyDotNetInterface = NULL;
if (S_OK != ::CoCreateInstance(TestComObject::CLSID_MyDotNetClass, NULL, CLSCTX_ALL, TestComObject::IID_IMyDotNetInterface, (void **)&ptrMyDotNetInterface))
{
 fprintf(stderr, "CoCreateInstance Failed\n");
 return 1;
}
ptrMyDotNetInterface->ShowCOMDialog();
ptrMyDotNetInterface->Release();


You will also need to include the .tlh file for the COM object (so the C/C++ can know about IID ect..., when using MSVC one can just use a #import and name the type lib (.tlb))

So on Linux one has to generate a .tlh (type lib header) from the managed assembly one way of doing that is the following:

  • Copy managed .dll to a Windows machine.
  • Generate type lib (.tlb) from the .dll (I suggest using tlbexp.exe, although you could use Regasm.exe as well)
  • in a C++ file #import type lib and compile the C++ file.

for example #import "C:\TestComObject.tlb" named_guids raw_interfaces_only This should write a .tlh file in the Output Directory.

  • modify the .tlh file so that it works with libcom ** TODO Write better instructions for this step **