正在DLL中注册回调函数
Registering callback function in DLL
我有一个简单的测试函数,我希望DLL中的代码回调
void user_function_stats( int )
{
cout << "Stats!n";
}
因此,在头文件中,我指定了一个typedef
typedef void (CALLBACK *stats_user_function)( int );
以及注册回调的DLL函数
void DLL_EXPORT getbar_client_set( stats_user_function pf );
这应该让我在用户代码中注册回调函数为
getbar_client_set( & user_function_stats );
但是编译器抱怨
main.cpp|14|error: invalid conversion from 'void (*)(int)'
to 'stats_user_function
{aka void (__attribute__((__stdcall__)) *)(int)}' [-fpermissive]|
我已经尝试将CALLBACK添加到用户功能的定义中
void CALLBACK user_function_stats( int )
{
cout << "Stats!n";
}
但是现在我得到了这个编译错误
undefined reference to `_imp__getbar_client_set'|
该令牌CALLBACK
实际上是Windows的调用约定说明符。它不必用于进行回调。Windows内部只是对回调使用不同的调用约定,而不是标准的C/C++调用约定。你可以做两件事中的任何一件。
您可以从typedef中删除CALLBACK
令牌,即
typedef void (*stats_user_function)( int );`
或者用CALLBACK
标记声明回调函数,该标记扩展为__stdcall__
调用约定说明符,即
void CALLBACK user_function_stats( int )
{
cout << "Stats!n";
}
相关文章:
- 正在为Xtensa simcall函数编写回调函数
- 如何在C++中使用非静态成员函数作为回调函数
- 从不同的 cpp 调用回调函数会导致bad_function_call
- 如果 C 函数仍然可以间接执行(通过回调函数),那么将它声明为静态函数是否是一种不好的做法?
- C 回调函数在对象 pascal 上崩溃
- 类 Referention 中C++回调函数引用非静态函数
- CURLOPT_INTERLEAVEFUNCTION回调函数始终接收 nullptr 作为用户数据指针
- 动态链接库中C++回调函数
- 我想制作设置鼠标回调函数,以便在仍然按下鼠标左键时连续传递坐标
- 使用回调函数从构造函数调用虚拟/派生方法的替代方法?
- 我可以使用谷歌 v8 在回调函数中获取 JavaScript 函数C++源文本吗?
- 重写另一个方法 [C++] 使用的超类回调函数
- 是否可以影响 C++ 中回调函数的局部变量?
- C++ Qt5 中带有 pigpio 库的回调函数
- 在定时器回调函数中使用 Sleep() 会导致C++出现问题吗?
- C++在赋值或回调函数时重载模板
- 如何用不同的参数类型和数字回调函数
- 如何为Python Swigged C++对象创建和分配回调函数
- 用回调函数替换C++正则表达式
- C++带有回调函数的模板类