我在 C++ 中有这个功能
extern "C" __declspec(dllexport) void SendPacketToServer(BYTE *packet, int Length)
{
_SendToServer(packet, Length);
}
如何在 C# 中使用它?
到目前为止我试过这个:
[DllImport("DAFramework 1.0.dll", SetLastError = true)]
internal static extern void SendPacketToServer(IntPtr packet, int length);
unsafe
{
fixed (byte* pByte = new byte[] { 0x13, 0x00 })
{
IntPtr data = new IntPtr((void*)pByte);
SendPacketToServer(data, 2);
}
}
我做错了什么吗?如果是这样,我怎样才能使它工作?我收到错误:Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
我可以用更简单的方法吗?