Marshal.GetFunctionPointerForDelegate Method
Assembly: mscorlib (in mscorlib.dll)
Parameters
- d
The delegate to be passed to unmanaged code.
Return Value
An System.IntPtr value that can be passed to unmanaged code, which in turn can use it to call the underlying managed delegate.- SecurityPermission for permission to call unmanaged code. Associated enumeration: UnmanagedCode Security action: LinkDemand
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
GetFunctionPointerForDelegate returns a pointer that is only ready for __stdcall calling convention. Then, if it is used in a callback scenario, the callback must use __stdcall calling convention, as all of the Windows callbacks does. If you use a 3rd party library that uses non __stdcall callbacks you will get strange malfunctions.
For example, if you need a callback that has the signature "bool Notification(char a,int b);", that function MUST use __stdcall convention and when using in a C++/CLI scenario, the casting must be explicitly done:
IntPtr p=Marshal::GetFunctionPointerForDelegate(theDelegate);
bool (__stdcall *pfnc)(char,int)=(bool (__stdcall*)(char,int))p;
InstallCallback(pfnc); //InstallCallback receives a native callback whit "bool fnc(char,char)" signature.
- 2/23/2008
- RFOG
- 8/19/2010
- Thomas Lee
- 5/23/2008
- Shri Borde