Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / September 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alex - 07 Sep 2007 16:25 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++.

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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.