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++ / June 2007

Tip: Looking for answers? Try searching our database.

Using C++/CLI wrapper to call .NET assembly from native code?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cctv.star@gmail.com - 29 Jun 2007 15:48 GMT
I need to dynamically load and call .NET assembly from native
application, written in C++.

I'm trying to do this by creating a (managed) module, written in C++/
CLI, whose header can be #included from native code like normal C++
header, and whose .cpp file uses C++/CLI to actually load and
call .NET assembly.

It kind of works right now, but not exactly how I want it to. Ideally,
I want to have something like a C++ wrapper class, which hides behing
its public interface all .NET stuff. In particular, I want the
lifetime of this wrapper to correspond to the time the .NET assembly
is loaded and accessible. The trouble is, a C++ class cannot contain
handles to any .NET objects. I cannot even create a global or static
handle. Right now evey time I need to call the assembly, I need to
load it. How to overcome this limitation?

I suspect I can wrap all .NET stuff in COM, but ideally I'd like to
stay away from (directly) calling COM and use C++/CLI instead.
Sheng Jiang[MVP] - 29 Jun 2007 20:30 GMT
>The trouble is, a C++ class cannot contain handles to any .NET objects.
This is not true, you can search for "How to: Declare Handles in Native
Types" in MSDN.

Signature

Sheng Jiang
Microsoft MVP in VC++

> I need to dynamically load and call .NET assembly from native
> application, written in C++.
[quoted text clipped - 15 lines]
> I suspect I can wrap all .NET stuff in COM, but ideally I'd like to
> stay away from (directly) calling COM and use C++/CLI instead.
Ben Voigt [C++ MVP] - 29 Jun 2007 22:10 GMT
> >The trouble is, a C++ class cannot contain handles to any .NET objects.
> This is not true, you can search for "How to: Declare Handles in Native
> Types" in MSDN.

or the documentation for gcroot<T>

>> I need to dynamically load and call .NET assembly from native
>> application, written in C++.
[quoted text clipped - 15 lines]
>> I suspect I can wrap all .NET stuff in COM, but ideally I'd like to
>> stay away from (directly) calling COM and use C++/CLI instead.

Rate this thread:







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.