C#调用c++的dll 回调使用方法

来源:互联网 发布:linux c mkdir函数 编辑:程序博客网 时间:2024/06/17 00:46

C#调用 代码

//声明

public delegate void MyDllCall(string buf,int size);

 

//设置回调函数
 [DllImport("MatrixCtrl.dll", EntryPoint = "MatrixSetCallback")]
 static extern bool MatrixSetCallback(MyDllCall fa);

 

//声明回调的函数

public void FunA(string buf, int size)
        {
            MessageBox.Show(buf);
            return ;
        }

//调用

 MatrixSetCallback(FunA);

 

 

C++dll

 

//声明

typedef bool (CALLBACK *MatrixReceive)(char *pBuf, int nBufSize);

MatrixReceive m_RecInfoCall ;  //回复信息的回调函数

 

 

/************************************************************************/
/*设置回调函数
*/
/************************************************************************/
extern "C"__declspec(dllexport)BOOL WINAPI MatrixSetCallback(MatrixReceive InfoReceive)
{
 g_MFCMatrix.m_RecInfoCall = InfoReceive;
 return TRUE;
}

 

g_MFCMatrix类中调用

m_RecInfoCall(recv,nLen);   //recv 为 char *, nLen 为 int

 

0 0
原创粉丝点击