原始代理声明
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);