Share via


Wrapping Delegates and Unmanaged Function Pointers

The .NET Framework version 2.0 and later provides the ability to marshal function pointers between managed and unmanaged code using the following methods:

  • Use the Marshal.GetDelegateForFunctionPointer method to marshal an unmanaged function pointer into a delegate. This method uses the System.IntPtr class to represent an unmanaged function pointer.

  • Use the Marshal.GetFunctionPointerForDelegate method to marshal a delegate into a function pointer that is callable from unmanaged code. When you use this method, you must manually keep the delegate from being collected by the garbage collector. The garbage collector does not track references to unmanaged code.

Note that the parameter marshaler can also marshal function pointers to delegates in the .NET Framework 2.0 and later.

See Also

Reference

GetDelegateForFunctionPointer

GetFunctionPointerForDelegate