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++ / November 2004

Tip: Looking for answers? Try searching our database.

Passing a callback to the unmanaged class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sasha Nikolic - 29 Nov 2004 08:34 GMT
I have one unmanaged and one managed class in the same vc++ project. Managed
object creates one instance of unmanaged class and needs to pass a callback
reference so that unmanaged class can periodically call the managed class's
method (without holding the reference to the managed object).

Can anybody please provide me with a short example or a basic idea?

Thanks a lot,
Sasha
Jochen Kalmbach - 29 Nov 2004 10:38 GMT
Hi Sasha Nikolic,

> I have one unmanaged and one managed class in the same vc++ project.
> Managed object creates one instance of unmanaged class and needs to
> pass a callback reference so that unmanaged class can periodically
> call the managed class's method (without holding the reference to the
> managed object).

How should the unmanaged class know with managed object to call if you do
not want to store the reference in the unmanaged object?

TO stare an managed object-reference in unmanaged code, you can use the
gcroot template.

See: Consuming Unmanaged C++ Class Libraries from .NET Clients
http://www.codeguru.com/Cpp/Cpp/cpp_managed/interop/article.php/c6867/

See: 16.3 __gc Pointers in Unmanaged Classes
http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/vcmxspec/html/vcManagedExtensionsSpec_16_3.asp

Signature

Greetings
 Jochen

  My blog about Win32 and .NET
  http://blog.kalmbachnet.de/

Sasha Nikolic - 30 Nov 2004 08:06 GMT
Thanks Jochen,  codeguru example is excellent! I needed very similar
solution.

> Hi Sasha Nikolic,
>
[quoted text clipped - 16 lines]
> http://msdn.microsoft.com/library/default.asp?url=/library/en-
> us/vcmxspec/html/vcManagedExtensionsSpec_16_3.asp

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.