C#返回byte[]给dll的方法,寻求帮助
2017-01-19 07:12
423 查看
谁能帮下我。我是新手中的新手,第一次用C++,目前只想解决这个问题
我现在的需求是,DLL里调用了C#的委托函数,委托函数返回字节数组给DLL,DLL再接下去处理
这个C#的委托函数的代码
这里是C++ 写的DLL代码
谢谢大家,我对C++不了解,希望能好人做到底,在我的基础上改代码,给提示我,我也不懂的,免得若大家烦。
谢谢谢谢谢谢!!
我现在的需求是,DLL里调用了C#的委托函数,委托函数返回字节数组给DLL,DLL再接下去处理
这个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++ 写的DLL代码
//这行前面的int 类型应该改成什么才能接收C#返回IntPtr类型 typedef int (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 = _msend(temp, len);//这里要怎么做才能把C#返回的IntPtr指针内容读取并转成char * //重点在这一部分。怎么实现我要的功能 //第一个参数aa就是上面上行从C#返回的字节数组的char * int ret = g_trueSend(aa, len); delete temp; }
谢谢大家,我对C++不了解,希望能好人做到底,在我的基础上改代码,给提示我,我也不懂的,免得若大家烦。
谢谢谢谢谢谢!!
相关文章推荐
- C# 调用C++ dll 方法返回char* 乱码
- C#反射动态调用dll中的方法,并返回结果
- c#调用c++写成的dll文件,返回char*,返回数组,用ref接收,byte[] (zz)
- C#反射动态调用dll中的方法,并返回结果[转]
- C#反射动态调用dll中的方法,并返回结果
- c#调用c++写成的dll文件,返回char*,返回数组,用ref接收,byte[] (zz)
- android 接收 C# 写的服务返回的byte[]方法
- C#反射动态调用dll中的方法,并返回结果
- C#反射动态调用dll中的方法,并返回结果
- c#调用c++写成的dll文件,返回char*,返回数组,用ref接收,byte[]
- C#反射动态调用dll中的方法,并返回结果
- 安装IE8在控制面板里面删除之后进不去桌面,提示找不到-IESetting.dll 解决办法(解决IE8卸载不了的问题,返回IE7 ,返回IE6),从IE8回到IE7的方法.
- .net调用DLL,返回不固定“结构”类型数据的方法
- C#调用VC的DLL时AfxGetApp失败的解决方法
- C#实现反射调用动态加载的DLL文件中的方法
- 用C#生成Excel文件的方法和Excel.dll组件生成的方法
- C#利用winmm.dll中的mciSendString方法录音
- asp.net C# 一个方法返回多个结果
- 用C#生成Excel文件的方法和Excel.dll组件生成的方法
- c#引用.dll文件后,如何显示dll里方法的解释