C++函数指针错误

标签 c++ function pointers

我正在尝试使源代码工作

extern "C" {
    typedef LRESULT (__stdcall *NRI_PM_CALLBACK)(WPARAM, LPARAM);
}

LRESULT OnPaymentManagerMessage(WPARAM wParam, LPARAM lParam)
{
    int type = (wParam >> 4) & 0x0F;
    int device = wParam & 0x0F;
    //cstr.Format("** Msg **[ %d %d %d ]", type, device, lParam);
    //handle message here
    return lParam;
}

NRI_PM_CALLBACK callback = &OnPaymentManagerMessage; //error on this line 

错误:“LRESULT (*)(WPARAM wParam, LPARAM lParam)”类型的值不能用于初始化“NRI_PM_CALLBACK”类型的实体

我在 Visual Studio Express 2012 中运行它

有什么想法吗?

谢谢

最佳答案

使 OnPaymentManagerMessage() 成为一个 __stdcall 函数:

LRESULT __stdcall OnPaymentManagerMessage(WPARAM wParam, LPARAM lParam) 
/* ... */

__cdecl 是编译器的默认设置(尽管编译器选项可以更改它)。

关于C++函数指针错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15130847/

相关文章:

C++ - 在文件末尾写入并跳过其余部分

string - 调用带有特殊前缀/后缀的函数

c++ - 函数模板参数的类型推导

c - 在 C 中使用指针时为 "lvalue required as left operand of assignment"

c - 缓冲区上的基名进入段错误

c++ - 在 C++ 中使用 delete 时出现段错误

c++ - 文件写入期间磁盘已满。我怎样才能收到有关此事的通知?

javascript - v8 对对象生命周期的困惑

c++ - 如何在qt中修复 "No query Unable to fetch row"

javascript - 为什么单击不同的按钮时会出现相同的数组值?