The following table shows examples of how a managed delegate can be marshaled to a function pointer in unmanaged code.
public delegate int EnumDelegate(
IntPtr hwnd, int LParam);
[DllImport("coredll.dll")]
static extern int EnumWindows(
EnumDelegate d,
Int lParm);
|
typedef BOOL (* WNDENUMPROC)
(HWND, LPARAM);
BOOL EnumWindows(
WNDENUMPROC lpEnumFunc,
LPARAM lParam);
|
public delegate int EnumDelegate(
IntPtr hwnd, int lParam);
[DllImport("coredll.dll")]
static extern int EnumWindows(
[MarshalAs(UnmanagedType.FunctionPtr0]
EnumDelegate d,
Int lParam);
|
typedef BOOL (* WNDENUMPROC)
(HWND, LPARAM);
BOOL EnumWindows(
WNDENUMPROC lpENumFunc,
LPARAM lParam);
|
See Also
Other Resources
Marshaling Support