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

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
 
B

Brian Muth

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
 
A

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

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
 
S

SvenC

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.
 
B

Ben Voigt [C++ MVP]

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top