C2440无法在C ++ WinApi中将LRESULT转换为WNDPROC [英] C2440 Can't convert LRESULT to WNDPROC in C++ WinApi

查看:457
本文介绍了C2440无法在C ++ WinApi中将LRESULT转换为WNDPROC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用WinApi写这个win32程序,我被困住,因为我下面的教程似乎有一个问题。

I'm trying to write this win32 program with WinApi and I'm stuck because the tutorial I'm following seems to have a problem.

MainWindow.h :

MainWindow.h:

class MainWindow
{
  public:
    MainWindow(HINSTANCE);
   ~MainWindow(void);

    LRESULT CALLBACK WndProcedure(HWND, UINT, WPARAM, LPARAM);

    // [...]

MainWindow.cpp:

MainWindow.cpp:

MainWindow::MainWindow(HINSTANCE hInstance) : hwnd(0)
{
  WNDCLASSEX WndClsEx;
  // [...]
  WndClsEx.lpfnWndProc = &MainWindow::WndProcedure;
  // [...]
}

LRESULT CALLBACK MainWindow::WndProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
  // [...]
}



我必须引用MainWindow :: WndProcedure错误,因为我遵循的签名完全符合教程说,但是lpfnWndProc行在构造函数中给出一个编译时错误:

I must be referencing MainWindow::WndProcedure wrong because I'm following the signature exactly as the tutorial says, however the lpfnWndProc line in the constructor gives a compile-time error:

错误C2440: '=':无法从'LRESULT(__stdcall MainWindow :: *)(HWND,UINT,WPARAM,LPARAM)'转换为'WNDPROC'

error C2440: '=' : cannot convert from 'LRESULT (__stdcall MainWindow::* )(HWND,UINT,WPARAM,LPARAM)' to 'WNDPROC'

推荐答案

替换

LRESULT CALLBACK WndProcedure(HWND, UINT, WPARAM, LPARAM);

static LRESULT CALLBACK WndProcedure(HWND, UINT, WPARAM, LPARAM);

此指针是函数调用中的一个隐藏参数,通过声明它静态this指针不是一个参数和两个函数的签名匹配。

The this pointer is a hidden parameter in your function call and by declaring it static the this pointer is not a parameter anymore and the signature of the two functions match.

这篇关于C2440无法在C ++ WinApi中将LRESULT转换为WNDPROC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆