出口C&x2B+;以回调函数作为参数的函数 我在DLL中有一个叫做doAlWork的C++函数。 它周围有一个c#包装。 我在C.*包装器中创建了一个委托,并将它作为回调函数传递给DLL中的C++函数。
我的c#代码如下:出口C&x2B+;以回调函数作为参数的函数 我在DLL中有一个叫做doAlWork的C++函数。 它周围有一个c#包装。 我在C.*包装器中创建了一个委托,并将它作为回调函数传递给DLL中的C++函数。,c#,c++,callback,C#,C++,Callback,我的c#代码如下: public delegate int UpdateDelegate(int status); public static int UpdateDelegate(int status) { return status; } [DllImport(_dllLocation)] public static extern in
public delegate int UpdateDelegate(int status);
public static int UpdateDelegate(int status)
{
return status;
}
[DllImport(_dllLocation)]
public static extern int DoAllWork( string param1, string param 2,... UpdateDelegate callbackproc);
}
EXPORT_FUNC Init(const char* path)
{
cppLibrary = new CPPLibrary();
return cppLibrary->Init(path);
}
EXPORT_FUNC DoAllWork(string param1, string param 2,...,
int(*statusfunction(int))
)
{
return cppLibrary->DoAllWork(string param1, string param 2,..., ??????);
}
我在C++头文件中声明doAcWork函数,并在CPP文件中实现如下:
public delegate int UpdateDelegate(int status);
public static int UpdateDelegate(int status)
{
return status;
}
[DllImport(_dllLocation)]
public static extern int DoAllWork( string param1, string param 2,... UpdateDelegate callbackproc);
}
EXPORT_FUNC Init(const char* path)
{
cppLibrary = new CPPLibrary();
return cppLibrary->Init(path);
}
EXPORT_FUNC DoAllWork(string param1, string param 2,...,
int(*statusfunction(int))
)
{
return cppLibrary->DoAllWork(string param1, string param 2,..., ??????);
}
.h文件:
int DoAllWork(string param1, string param 2,... int (*statusfunction(int))
.cpp文件:
int DoAllWork(string param1, string param 2,... int (*statusfunction(int))
{
//do work;
}
然后我们从一个名为ExpalAlp.CPP的第三个CPP文件导出C++函数DoAllWork 代码如下:
public delegate int UpdateDelegate(int status);
public static int UpdateDelegate(int status)
{
return status;
}
[DllImport(_dllLocation)]
public static extern int DoAllWork( string param1, string param 2,... UpdateDelegate callbackproc);
}
EXPORT_FUNC Init(const char* path)
{
cppLibrary = new CPPLibrary();
return cppLibrary->Init(path);
}
EXPORT_FUNC DoAllWork(string param1, string param 2,...,
int(*statusfunction(int))
)
{
return cppLibrary->DoAllWork(string param1, string param 2,..., ??????);
}
我的问题是,无论我以何种方式尝试传递最后一个参数(int(*statusfunction(int))的参数,我都会得到一个错误
<>在导出一个带有回调函数的参数的C++函数时,如何传递参数?
谢谢不要让我们猜到您得到的是哪个错误……您得到的是编译时错误吗?运行时错误?具体是什么错误?