C#处理C++库回调报错_非托管代码传递委托被垃圾回收

检测到 CallbackOnCollectedDelegate
Message: 对“HBVideoParser!Videocomm.Video.HB.HBSDK+SrcDataParseCBHandler::Invoke”类型的已垃圾回收委托进行了回调。这可能会导致应用程序崩溃、损坏和数据丢失。向非托管代码传递委托时,托管应用程序必须让这些委托保持活动状态,直到确信不会再次调用它们。

 

        [DllImport("...")]
        public static extern bool HB_SDVR_SetParseCallBack(int lRealHandle, SrcDataParseCBHandler SrcDataParseCBFun, int nRseserved);

        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
        public delegate void SrcDataParseCBHandler(int nChl, System.IntPtr SrcDataBuf, int nSize, int nFrameType, VIDEO_TIME ets, int user);

        SrcDataParseCBHandler srcDataParseCBHandler ;
        public int Start()
        {
            ...

                srcDataParseCBHandler = OnSrcDataParseCBHandler;
                bool resb = HBSDK.HB_SDVR_SetParseCallBack(CookieID, srcDataParseCBHandler, CookieID);
    ...    

        }
 

  public void OnSrcDataParseCBHandler(int nChl, System.IntPtr SrcDataBuf, int nSize, int nFrameType,                                VIDEO_TIME ets, int user)
        {...}

 

posted @ 2009-12-18 10:12  joe62  阅读(4842)  评论(7编辑  收藏  举报