问题描述
错误信息:其他信息:对PInvoke函数“hk9600sdkTest!hk9600sdkTest.IVMS9600SDK::HikPt_StartPlayView”的调用导致堆栈不对称。原因可能是托管的PInvoke签名与非托管的目标签名不匹配。请检查PInvoke签名的调用约定和参数与非托管的目标签名是否匹配c++:typedefvoid(__stdcall*pStreamCallback)(longlSession,intiStreamType,constchar*data,intdataLen,void*pUser);HIKPT_EXTERNlongHIKPT_APIHikPt_StartPlayView(constchar*szCameraIndexCode,void*hWnd,pStreamCallbackpFun,void*pUserData);c#:声明publicdelegatevoidpStreamCallback(intlSession,intiStreamType,stringdata,intdataLen,IntPtrpUser);//实时流回调函数[DllImport(@"HikPlatformSDK.dll",CallingConvention=CallingConvention.StdCall)]//,CharSet=CharSet.UnicodepublicstaticexternintHikPt_StartPlayView(stringszCameraIndexCode,IntPtrhWnd,pStreamCallbackpFun,IntPtrpUserData);调用stringcamercode="11100095001310000003";preHand=IVMS9600SDK.HikPt_StartPlayView(camercode,panel1.Handle,null,IntPtr.Zero);MessageBox.Show(preHand.ToString());更换了调用方式和字符集都没有效果,在线急等
解决方案
解决方案二:
__stdcall
解决方案三:
[UnmanagedFunctionPointer(CallingConvention.StdCall)]publicdelegatevoidpStreamCallback(intlSession,intiStreamType,stringdata,intdataLen,IntPtrpUser);
解决方案四:
@"HikPlatformSDK.dll",这个是不是多余preHand=IVMS9600SDK.HikPt_StartPlayView(camercode,panel1.Handle,null,IntPtr.Zero);其中IVMS9600SDK是一个对象,还是一个静态类?这句似乎是直接调用publicstaticexternintHikPt_StartPlayView(stringszCameraIndexCode,IntPtrhWnd,pStreamCallbackpFun,IntPtrpUserData);