首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#调用C++ 写的dll解决思路

2012-03-01 
C#调用C++ 写的dll执行到C++内某个函数的时候,会报Attempted to read or write protected memory. This is

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 试试看

热点排行