您的位置:首页 > 编程语言 > C#

C#调用C回调函数后,程序奔溃问题

2015-09-15 19:40 323 查看
原始代理声明

delegate void DlgVideoStreamCallBack(IntPtr pData, int size, int height, int width, IntPtr pUserData);


C函数导入

[DllImport("peerclient.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "Webrtc_ResigsterLocalVideoCallBack")]
public static extern void Webrtc_ResigsterLocalVideoCallBack(DlgVideoStreamCallBack callback, int thread_id);


回调函数

static void LocalVideoStreamCallBack(IntPtr pData, int size, int height, int width, IntPtr pUserData)
{

}


使用上面的方式,会导致C#在调用完后,释放pData内容,导致C程序崩溃

所以在声明代理的时候,说明是C回调,不回收里面资源

修改后代理

[System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.Cdecl)]
delegate void DlgVideoStreamCallBack(IntPtr pData, int size, int height, int width, IntPtr pUserData);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: