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