|
3驿站币
下面是C#的代码
- static IntPtr sendDataFun(IntPtr buf, int len)
- {
- byte[] buffer = new byte[len];
- Marshal.Copy(buf, buffer, 0, len);
- //此处是各种处理。。省略
-
- //获取buffer字节数组的内存地址
- IntPtr pin = GCHandle.ToIntPtr(GCHandle.Alloc(buffer));
- return pin;//把内存地址返回给DLL
- }
复制代码
这里是C++的代码,问题就在这里
- //这行前面的void* 类型可以接收C#返回字节数组指针IntPtr类型吗?
- typedef void* (WINAPI *mhook_func)(char* buf, int len);//这个结构就是下面_msend函数的
- int WINAPI send(const char *buf, int len)
- {
- char *temp = new char[len];
- memcpy_s(temp, len, buf, len);
-
- //_msend就是C#的委托函数(sendDataFun),先将temp和len发送给C#的处理,再返回字节数组,再转成 char *
- char * aa =(char *)_msend(temp, len);//这里要怎么做才能把C#返回的IntPtr指针内容读取并转成char *
- //重点在这一部分。怎么实现我要的功能
-
- //第一个参数aa就是上面上行从C#返回的字节数组的char *
- int ret = g_trueSend(aa, len);
- delete temp;
- }
复制代码 |
上一篇: 如何利用DEV C++中的窗体程序显示网页内容下一篇: 谁有fiddler发我一份
|