C#调用C++/CLI本地代码的回调函数

yeaphi yeaphi 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
c++ dll
CClientGlobal.h
class __declspec(dllexport) CClientGlobal
{
public:
typedef int (*pMsgHandleResponseFunc)(CMsg*,vector<CMsg*>&);
typedef int (*pRequestTimeOutFunc)(int _CMDID);
void Set_Response(pMsgHandleResponseFunc fp){};
void Set_Timeout(pRequestTimeOutFunc fp){};
void Set_Response(void* p){};
void Set_Timeout(void* p){};
}

c++/cli wrapper 库
native head
CClientGlobal.h
class __declspec(dllexport) CClientGlobal
{
public:
typedef int (*pMsgHandleResponseFunc)(CMsg*,vector<CMsg*>&);
typedef int (*pRequestTimeOutFunc)(int _CMDID);
void Set_Response(pMsgHandleResponseFunc fp){};
void Set_Timeout(pRequestTimeOutFunc fp){};
void Set_Response(void* p){};
void Set_Timeout(void* p){};

}

wrapper head
public ref class CClientGlobalWrapper
{
CClientGlobal* NativeClientGlobal;
public:
CClientGlobalWrapper(void);
~CClientGlobalWrapper();
public: //消息发送

typedef int (*pMsgHandleResponseFunc)(CMsg*,vector<CMsg*>&);
typedef int (*pRequestTimeOutFunc)(int _CMDID);


void Set_Response(void* fp);
void Set_Response(pMsgHandleResponseFunc fp);


void Set_Timeout(void* fp);
void Set_Timeout(pRequestTimeOutFunc fp);
};



我没有使用显示声明dll函数的方式,而是在C#中添加C++/cli封装的dll,
CClientGlobalWrapper cgw = new CClientGlobalWrapper();
pMsgHandleResponseFunc msgh = new pMsgHandleResponseFunc(MsgHandle);
cgw.Set_Response() 方法只能看到void*的参数,而看不到函数指针的参数


有没有兄弟有这方面经验的,请帮忙解决一下
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
yeaphi
C# 111,128 成员 642,537 内容