The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Calling managed functions from unmanaged code

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Roy Osherove

Posts: 1807
Nickname: royo
Registered: Sep, 2003

Roy Osherove is a .Net consultant based in Israel
Calling managed functions from unmanaged code Posted: Mar 10, 2004 4:38 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Roy Osherove.
Original Post: Calling managed functions from unmanaged code
Feed Title: ISerializable
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/rosherove/Rss.aspx
Feed Description: Roy Osherove's persistent thoughts
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Roy Osherove
Latest Posts From ISerializable

Advertisement
Our company has an internal mailing list of important and interesting things. Sometimes I'll grab some technical gems from there and post them for everyone's benefit.
For example:
 
Q:“I have a static method in managed code that I’d like to call from unmanaged code. Is there any recommended way of doing this?”
 
A:“This is easily doable...just create a delegate in managed code and pass it to unmanaged code.  It will turn into a callable function pointer on the unmanaged side.  Couple of things to be aware of:
 
1) Make sure the function pointer definition on the unmanaged side uses __stdcall.  Weird and bad things will happen if you try to use a different calling convention.
2) Make sure you keep the delegate alive on the managed side somehow (easiest way is to assign a static variable to it).  #1 mistake when doing this is letting the delegate go out of scope...the GC will collect it, and Bad Things(tm) will happen when the unmanaged side tries to invoke the function pointer.“
 
 

Read: Calling managed functions from unmanaged code

Topic: Need to do Demos very fast? Go offline. Previous Topic   Next Topic Topic: New Service Pack for Office

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use