看看这个对你是否有帮助?
声明如下:
[DllImport("kernel32.dll", SetLastError=true)] static extern int CreateMailslotA ( string lpName, int nMaxMessageSize, int lReadTimeout, ref SECURITY_ATTRIBUTES lpSecurityAttributes)  
struct SECURITY_ATTRIBUTES{
 int nLength;
 int lpSecurityDescriptor;
 int bInheritHandle;
}

解决方案 »

  1.   

    未处理的“System.NullReferenceException”类型的异常出现在 TopLog.exe 中。其他信息: 未将对象引用设置到对象的实例。
      

  2.   

    你首先定义一个这样的结构,然后定义一个这个结构的实例,将这个结构实例赋为null试试呢public struct LPSECURITY_ATTRIBUTES{}LPSECURITY_ATTRIBUTES  aa = new LPSECURITY_ATTRIBUTES();
    aa = null;CreateMailslot(m_strSlotName, 10000, 400, aa );
      

  3.   

    那你先要实例化第四个参数啊:
    LPSECURITY_ATTRIBUTES xxx=new LPSECURITY_ATTRIBUTES();
    然后用这个去调用函数啊:
    CreateMailslot(m_strSlotName, 10000, 400, xxx);
      

  4.   

    谢谢楼上的朋友,首先aa=null不编译。我这样还是不行。
    m_strSlotName = @"\\\\.\\mailslot\\XDLGT"; LPSECURITY_ATTRIBUTES lpSa = new LPSECURITY_ATTRIBUTES();
    lpSa.nLength = 0;
    lpSa.bInheritHandle = false;
    lpSa.lpSecurityDescriptor = 0; m_hSlot = CreateMailslot(m_strSlotName, 10000, 400, lpSa);
    if (m_hSlot.ToInt32()<=0)
    AddErr("未能成功创建邮槽");
      

  5.   

    这是我试的,结果是正确的,代码如下:
    public struct SECURITY_ATTRIBUTES
    {
    public int nLength;
    public int lpSecurityDescriptor;
    public int bInheritHandle;
    };[DllImport("kernel32.dll", SetLastError=true)] 
    static extern int CreateMailslotA ( string lpName, int nMaxMessageSize, int lReadTimeout, ref SECURITY_ATTRIBUTES lpSecurityAttributes);  调用如下
    string m_strSlotName = "\\\\.\\mailslot\\XDLGT";
    SECURITY_ATTRIBUTES lpSa = new SECURITY_ATTRIBUTES();
    lpSa.nLength = 0;
    lpSa.bInheritHandle = 0;
    lpSa.lpSecurityDescriptor = 0;int m_hSlot = CreateMailslotA(m_strSlotName, 10000, 400, ref lpSa);