c#调用DLL中char*(图像),使用intptr但是没有返回值,且调用至函数运行时 exe停止运行

.Net技术 码拜 7年前 (2017-05-06) 1637次浏览
C++的dll 文件 函数声明
DWORD  H264_PLAY_CatchPicBuf(LONG nPort, char* pBuf,LONG len,LONG *width,LONG *height,long ntype=0)
本人的C# 导入 函数声明
[DllImport(“H264Play.dll”)]
public static extern int H264_PLAY_CatchPicBuf(int nPort,ref  IntPtr buf,int len, ref int pwidth, ref int pheight,int type=0);

C#程序中的变量定义
public IntPtr ImgBuf =  Marshal .AllocHGlobal(928*576*3);
int getc = XMSDK.H264_PLAY_CatchPicBuf(1,ref ImgBuf,928*576*3,ref ImgWidth, ref ImgHeight, 0);
相关的变量,用到的部分就是上面这些
但是返回值,只有width和height,图像的buf为空。
而且调试运行至调用函数这句,报错, (。exe停止运行)
问:1. 本人是不是imgbuf定义错了,或使用错了,没有返回值
2.本人分配的空间太大导致的 停止运行 报错?

解决方案

20

pBuf传个byte[]进去,LONG对应long。
原因是不清楚c++代码怎么写的,只能试。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明c#调用DLL中char*(图像),使用intptr但是没有返回值,且调用至函数运行时 exe停止运行
喜欢 (0)
[1034331897@qq.com]
分享 (0)