Exposing unmanaged C++ COM to managed C++ application

  • Thread starter Thread starter Alex
  • Start date Start date
A

Alex

Hi, everybody,

I found some simple example of writing of a service application in
managed C++. The only thing my service has to do is periodically to
call some COM Server function written in managed C++.

If I had to expose the interface of my COM Server to unmanaged C++, I
could've simply used:
#include <atlbase.h>
#include "MyCOMServer_i.h"
#include "MyCOMServer_i.c"
..................
...................
...................
In C# I believe, I can "Add Reference" ..

So my question is how can I expose functions of unmanaged C++ COM
to the managed C++ application? Or this is not a trivial task?

Thanks,
Alex
 
Calling COM objects from managed C++ is trivial, since one can readily mix managed and unmanaged code.

Just call CoCreateInstance and go to town.

If you prefer to code managed code only, then "Add Reference" and select the COM tab.

Brian
 
Calling COM objects from managed C++ is trivial, since one can readily mix managed and unmanaged code.

Just call CoCreateInstance and go to town.

If you prefer to code managed code only, then "Add Reference" and select the COM tab.

Brian

Maybe I wasn't clear in my first post... but
a) I know that I can AddReference in C# project, but I cannot find
this menu item in my C++ project GUI.

b) before I can call CoCreateInstance in my unmanaged application I
use corresponding "#include", I cannot do this in managed project, so
how can I replace this #include in managed C++ project?

Thanks
 
Hi Alex,
Maybe I wasn't clear in my first post... but
a) I know that I can AddReference in C# project, but I cannot find
this menu item in my C++ project GUI.

Right click on the project in the solution explorer, there you find Add
Reference
b) before I can call CoCreateInstance in my unmanaged application I
use corresponding "#include", I cannot do this in managed project, so
how can I replace this #include in managed C++ project?

You can use the #import statement to generate wrapper classes based on the
type library of your COM objects.
Check MSDN for details.
 
Alex said:
Hi, everybody,

I found some simple example of writing of a service application in
managed C++. The only thing my service has to do is periodically to
call some COM Server function written in managed C++.

You have a managed service calling a managed library? Forget about COM, use
the .NET classes directly.
If I had to expose the interface of my COM Server to unmanaged C++, I
could've simply used:
#include <atlbase.h>
#include "MyCOMServer_i.h"
#include "MyCOMServer_i.c"
..................
..................
..................
In C# I believe, I can "Add Reference" ..

So my question is how can I expose functions of unmanaged C++ COM
to the managed C++ application? Or this is not a trivial task?

Unmanaged COM you can call the same as always, what makes you think that
#include won't work?
 
Back
Top