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++ / March 2006

Tip: Looking for answers? Try searching our database.

[C++/CLI] Callback from unmanaged to managed

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Remi THOMAS [MVP] - 28 Mar 2006 09:43 GMT
Hi,

I did spend quite a long time finding how to call managed code from
unmanaged C++ class.
Here is the my final code:
http://xtware.com/mcallback/mcallback.htm

Is it the best way to do it?
Does
mgt^ callback = (mgt^)GCHandle::FromIntPtr(IntPtr(m_callback)).Target;
take long time to execute?

Can we do it a better way?

Remi

ps: I'll publish optimal solution in codeproject, there is so many people
having this question!
Willy Denoyette [MVP] - 28 Mar 2006 10:24 GMT
I don't get the point, nothing in this sample is unmanaged code, everything
gets compiled to IL.
What you are doing can just be done like this:

class umgt
{
public:

  void MyTreatment(mgt ^obj)
  {
      MyParameter ^param = gcnew MyParameter;
      param->m_value = 123;
      obj->MyCallback(param);
  }
};

So I don't think this illustrates how to callback from unmanaged to managed.

Willy.

| Hi,
|
[quoted text clipped - 14 lines]
| ps: I'll publish optimal solution in codeproject, there is so many people
| having this question!
Jochen Kalmbach [MVP] - 28 Mar 2006 10:45 GMT
Hi Remi!

> I did spend quite a long time finding how to call managed code from
> unmanaged C++ class.
> Here is the my final code:
> http://xtware.com/mcallback/mcallback.htm
>
> Is it the best way to do it?

The easiest Solution is to use the "gcroot" template...
This is exactly designed for your purpose...
See:
http://groups.google.de/group/microsoft.public.dotnet.languages.vc/msg/577d07f35
22b5a25?hl=de
&

By the way:
Unmanaged in this context means: The class in not handled by the GC.
Unmanaged does not mean "native"...

Greetings
  Jochen
Remi THOMAS [MVP] - 28 Mar 2006 13:33 GMT
> Hi,

Thanks for your answer.

I was sure gcroot disapear with C++/CLI. It's badly classify in MSDN I
think.

#pragma unmanaged
MSND says "An unmanaged function will be compiled for the native
platform...", confusing isn't it?

Remi

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.