GetDelegateForFunctionPointer(TDelegate) Method (IntPtr)
Collapse the table of content
Expand the table of content

Marshal.GetDelegateForFunctionPointer<TDelegate> Method (IntPtr)


[Supported in the .NET Framework 4.5.1 and later versions]

Converts an unmanaged function pointer to a delegate of a specified type.

Namespace:   System.Runtime.InteropServices
Assembly:  mscorlib (in mscorlib.dll)

public static TDelegate GetDelegateForFunctionPointer<TDelegate>(
	IntPtr ptr


Type: System.IntPtr

The unmanaged function pointer to convert.

Return Value

Type: TDelegate

A instance of the specified delegate type.

Type Parameters


The type of the delegate to return.

Exception Condition

The TDelegate generic parameter is not a delegate, or it is an open generic type.


The ptr parameter is null.

You can use theGetDelegateForFunctionPointer<TDelegate>(IntPtr) andGetFunctionPointerForDelegate<TDelegate>(TDelegate)methods to marshal delegates in both directions.

TheGetDelegateForFunctionPointer<TDelegate>(IntPtr) method has the following restrictions:

  • You cannot pass an invalid function pointer to this method.

  • You can use this method only for pure unmanaged function pointers.

  • You cannot use this method with function pointers obtained through C++ or from the GetFunctionPointer method.

  • You cannot use this method to create a delegate from a function pointer to another managed delegate.


requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.5.1
Portable Class Library
Supported in: portable .NET platforms
Windows Phone
Available since 8.1
Return to top
© 2016 Microsoft