调用API的时候,如果一个结构体要设置为NULL,那在C#中应该如何实现啊?例如:   
HANDLE CreateEvent(
  LPSECURITY_ATTRIBUTES lpEventAttributes, 
  BOOL bManualReset, 
  BOOL bInitialState, 
  LPTSTR lpName 
); lpEventAttributes 
[in] Ignored. Must be NULL. 
这个C#中应该如何设置啊?谢谢

解决方案 »

  1.   

    应该也是把Structure中的那个值设置为null
      

  2.   

    这里的lpEventAttributes是一个指针,所以应该使用IntPtr,如果需要它为空,则用IntPtr.Zero
      

  3.   

    所以,函数声明为这个:
            [DllImport("Kernel32.dll", CharSet = CharSet.Auto)]
            public static extern IntPtr CreateEvent(
                IntPtr lpEventAttributes,
                bool bManualReset,
                bool bInitialState,
                string lpName);
    你在调用这个函数的时候可以这样:
     CreateEvent(IntPtr.Zero, false, true, “TRY”)
      

  4.   

    IntPtr.Zero 应该是 Reeezak(坚持信念) 说的