C#调用C++/CLI本地代码的回调函数
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*的参数,而看不到函数指针的参数
有没有兄弟有这方面经验的,请帮忙解决一下
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*的参数,而看不到函数指针的参数
有没有兄弟有这方面经验的,请帮忙解决一下
...全文
相关推荐
C#通过C++/CLI间接调用NativeCPP类的DLL文件
这样做的目的是让C#代码可以通过C++/CLI类调用原生函数。2.
C++调用C#类库,通过C++/CLI(CLR)作为中间层进行桥接
如何通过C++/CLI(CLR)作为中间层桥接C++和C#。
C++调用C#的DLL实例程序
使用C++/CLI调用C#方法:在C++/CLI代码中,引入C#命名空间,并创建对C#类的实例。然后,你可以像调用C++函数一样调用C#方法。
C#在C++中注册回调函数
C#定义回调函数和委托,通过P/Invoke暴露给C++;C++/CLI作为桥梁,将C++的函数指针转换为C#的委托;最后,C++调用C++/CLI方法,完成回调函数的注册。
C#调用C++的中间封装(CLR)
**引用C++/CLI库**:在C#项目中,添加对C++/CLI项目的引用。这会生成一个DLL文件,C#可以使用这个DLL来调用C++的代码。5.


