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
Brian Muth - 07 Sep 2007 20:06 GMT
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
Alex - 07 Sep 2007 22:37 GMT
> Calling COM objects from managed C++ is trivial, since one can readily mix managed and unmanaged code.
>
[quoted text clipped - 3 lines]
>
> 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
SvenC - 08 Sep 2007 10:33 GMT
Hi Alex,
>> Calling COM objects from managed C++ is trivial, since one can readily
>> mix managed and unmanaged code.
[quoted text clipped - 9 lines]
> 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.
--
SvenC
Ben Voigt [C++ MVP] - 11 Sep 2007 01:50 GMT
> 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:
[quoted text clipped - 8 lines]
> 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?
> Thanks,
> Alex