函数原型是这样的:Hik_PlayM4_SetDecCallBack(PORT,DecCBFun);
void CALLBACK DecCBFun(long nPort,char * pBuf,long nSize,FRAME_INFO * pFrameInfo, long nReserved1,long nReserved2);
我的项目是由:c++ Classlib(封装海康的mfc写的sdk,供.net平台下调用)和c# Applacation(客户端界面)组成.
如果直接调用一个回调函数API,我知道可以通过委托进行,但是这个项目里多了一个对于API打包封装的c++ Classlib,如何处理呢?
我得delegate是放在c++ Classlib还是c#里呢?如果放在c#里,c++ Classlib对于Hik_PlayM4_SetDecCallBack(PORT,DecCBFun)的封装如何进行,可以是其能够被c#顺利调用触发呢?
我糊涂了,请大家指教,谢谢
11 个解决方案
#1
委托
#2
楼上的太含糊了,我当然知道用委托了
#3
关注..
#4
我得delegate是放在c++ Classlib还是c#里呢?如果放在c#里,c++ Classlib对于Hik_PlayM4_SetDecCallBack(PORT,DecCBFun)的封装如何进行,可以是其能够被c#顺利调用触发呢?
========================================
委托放在C#可以.
Port 是什么类型??
========================================
委托放在C#可以.
Port 是什么类型??
#5
Port不用管他,设为0就行了,关键是在c++ Classlib里对于
Hik_PlayM4_SetDecCallBack(PORT,DecCBFun)的封装如何进行,使其能顺利被c#顺利调用触发
Hik_PlayM4_SetDecCallBack(PORT,DecCBFun)的封装如何进行,使其能顺利被c#顺利调用触发
#6
public void delegate DecCBFun( int nPort, string//or stringbuilder(看是如还是出的参数还有注意编码) pBuf, int nSize, FRAME_INFO//(这里还要在c#定义一个与c++FRAME_INFO内存布局一致的结构) pFrameInfo, int nReserved1, int nReserved2);
C#
[dllimport..... ]
Hik_PlayM4_SetDecCallBack( int ,DecCBFun)
DecCBFun dcf = new .... 委托
C#
[dllimport..... ]
Hik_PlayM4_SetDecCallBack( int ,DecCBFun)
DecCBFun dcf = new .... 委托
#7
楼上的
你的意思我完全明白,但是如果这样的话,那个c++lib岂不是没用了吗?
你的意思我完全明白,但是如果这样的话,那个c++lib岂不是没用了吗?
#8
所谓用c++ 封装为C#使用只是为了让c#可以访问原来c#无法访问的东东,例如c++的类。
#9
CallbackOnCollectedDelegate was detected
Message: A callback was made on a garbage collected delegate of type 'CAEPlayer!PlayerUI.FrmMain+DelDecCBFun::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.
直接调非托管代码不行吧?
函数原型:HIK_PLAYM4_API BOOL __stdcall Hik_PlayM4_SetDecCallBack(LONG nPort,void (CALLBACK* DecCBFun)(long nPort,char * pBuf,long nSize,FRAME_INFO * pFrameInfo, long nReserved1,long nReserved2));
Message: A callback was made on a garbage collected delegate of type 'CAEPlayer!PlayerUI.FrmMain+DelDecCBFun::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.
直接调非托管代码不行吧?
函数原型:HIK_PLAYM4_API BOOL __stdcall Hik_PlayM4_SetDecCallBack(LONG nPort,void (CALLBACK* DecCBFun)(long nPort,char * pBuf,long nSize,FRAME_INFO * pFrameInfo, long nReserved1,long nReserved2));
#10
自己顶
#11
关于海康的咋都是不了了之
#1
委托
#2
楼上的太含糊了,我当然知道用委托了
#3
关注..
#4
我得delegate是放在c++ Classlib还是c#里呢?如果放在c#里,c++ Classlib对于Hik_PlayM4_SetDecCallBack(PORT,DecCBFun)的封装如何进行,可以是其能够被c#顺利调用触发呢?
========================================
委托放在C#可以.
Port 是什么类型??
========================================
委托放在C#可以.
Port 是什么类型??
#5
Port不用管他,设为0就行了,关键是在c++ Classlib里对于
Hik_PlayM4_SetDecCallBack(PORT,DecCBFun)的封装如何进行,使其能顺利被c#顺利调用触发
Hik_PlayM4_SetDecCallBack(PORT,DecCBFun)的封装如何进行,使其能顺利被c#顺利调用触发
#6
public void delegate DecCBFun( int nPort, string//or stringbuilder(看是如还是出的参数还有注意编码) pBuf, int nSize, FRAME_INFO//(这里还要在c#定义一个与c++FRAME_INFO内存布局一致的结构) pFrameInfo, int nReserved1, int nReserved2);
C#
[dllimport..... ]
Hik_PlayM4_SetDecCallBack( int ,DecCBFun)
DecCBFun dcf = new .... 委托
C#
[dllimport..... ]
Hik_PlayM4_SetDecCallBack( int ,DecCBFun)
DecCBFun dcf = new .... 委托
#7
楼上的
你的意思我完全明白,但是如果这样的话,那个c++lib岂不是没用了吗?
你的意思我完全明白,但是如果这样的话,那个c++lib岂不是没用了吗?
#8
所谓用c++ 封装为C#使用只是为了让c#可以访问原来c#无法访问的东东,例如c++的类。
#9
CallbackOnCollectedDelegate was detected
Message: A callback was made on a garbage collected delegate of type 'CAEPlayer!PlayerUI.FrmMain+DelDecCBFun::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.
直接调非托管代码不行吧?
函数原型:HIK_PLAYM4_API BOOL __stdcall Hik_PlayM4_SetDecCallBack(LONG nPort,void (CALLBACK* DecCBFun)(long nPort,char * pBuf,long nSize,FRAME_INFO * pFrameInfo, long nReserved1,long nReserved2));
Message: A callback was made on a garbage collected delegate of type 'CAEPlayer!PlayerUI.FrmMain+DelDecCBFun::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.
直接调非托管代码不行吧?
函数原型:HIK_PLAYM4_API BOOL __stdcall Hik_PlayM4_SetDecCallBack(LONG nPort,void (CALLBACK* DecCBFun)(long nPort,char * pBuf,long nSize,FRAME_INFO * pFrameInfo, long nReserved1,long nReserved2));
#10
自己顶
#11
关于海康的咋都是不了了之