Groups | Blog | Home
all groups > dotnet sdk > january 2006 >

dotnet sdk : Calling .NET code from plain old C++ (COM)


David Thielen
1/12/2006 12:49:01 PM
Hi;

Can plain old C++ (not managed C++), used to write a COM object, instantiate
and call a .NET object?

And if there is anything special that has to be done, is there a url that
discusses it?

--
v-phuang NO[at]SPAM online.microsoft.com (
1/13/2006 6:29:50 AM
Hi Dave,

From you description, I understand that you want to know if we can call a
.NET object from C++ unmanaged code without exposing the .NET object to COM.
If I misunderstood, please feel free to let me know.

We can call a .NET object from C++ directly without exposing the .NET
object to COM. This technique is called "Hosting the Common Language
Runtime".
You can get started with the link below.
Hosting the Common Language Runtime
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconhostingcommonlanguageruntime.asp

In addition, you can take a look at the books below which discuss details
about the CLR runtime hosting.
Essential .NET, Volume I: The Common Language Runtime (Paperback) by Don
Box.
http://www.amazon.com/gp/product/0201734117/104-8200510-9027925?v=glance&n=2
83155

Customizing the Microsoft? .NET Framework Common Language Runtime
http://www.microsoft.com/MSPress/books/6895.asp

If you still have any concerns, please feel free to let me know.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
NuTcAsE
1/18/2006 9:03:04 AM
Peter,

I think david's question was how to create an instance of a .Net object
from a C++ COM component. In this case all he needs to do is a COM
callable wrapper for the .net assembly and use the CCW in the C++ COM
component to access the .net assembly.

David,

You should be able to use the tlbexp utility to create a com callable
wrapper for the .net assembly. Heres a link that describes the tlbexp
utility:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpgrfTypeLibraryExporterTlbExpexe.asp

Hope this helps...

NuTcAsE
AddThis Social Bookmark Button