日期:2014-05-18  浏览次数:20937 次

C#调用C++ 写的dll
执行到C++内某个函数的时候,会报
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

哪位高人指点一下是什么原因?

------解决方案--------------------
[DllImport("MsgQueue.dll")]
public static extern int OpenQueue(string QueuePath, int iType, IntPtr nNotifyWnd);
[DllImport("MsgQueue.dll")]
public static extern int Enqueue(string chMsg, int iMsgLen, bool bLastMsg, string chAttachMent);
[DllImport("MsgQueue.dll")]
public static extern int Dequeue([MarshalAs( UnmanagedType.LPArray )] byte[] chMsg,[MarshalAs(UnmanagedType.LPArray)] Int32[] pMsgLen,bool bMovePtr,IntPtr chattachment);
[DllImport("MsgQueue.dll")]
public static extern int CloseQueue(int iType);

恒多时候是声明的问题 实在不行用上 MarshalAs 试试看