How to pass a null pointer to a Win32 API in C # .Net?

I look at the RegisterHotKey function:

http://msdn.microsoft.com/en-us/library/ms646309(VS.85).aspx

BOOL RegisterHotKey( __in HWND hWnd, __in int id, __in UINT fsModifiers, __in UINT vk ); 

I used IntPtr to pass the first argument, which works fine in most cases. But now I need to consciously pass the null pointer as the first argument, which IntPtr (intentionally) will not do. I am new to .Net and it puzzled me. How can i do this?

+7
null c # pinvoke
source share
1 answer

Use IntPtr.Zero for NULL

For example:

 public void Example() { ... RegisterHotKey(IntPtr.Zero, id, mod, vk); } [DllImportAttribute("user32.dll", EntryPoint="RegisterHotKey")] [return: MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)] public static extern bool RegisterHotKey( IntPtr hWnd, int id, uint fsModifiers, uint vk); 
+15
source share

All Articles