有人可以帮我解决这个错误吗?我是 C++ 新手。看来错误就发生在一堆宏中。我能做什么来解决它?或者我怎样才能追踪到它的源头?
我真的不明白这个错误。这是否意味着编译器尝试将方法转换void ReadCPUparameter()为LRESULT funcName(WPARAM wParam, LPARAM lParam)函数头?
错误:
// error C2440: 'static_cast' : cannot convert from
// 'void (__thiscall CStartup::* )(void)' to
// 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'.
//
// ON_MESSAGE(WM_UPLOAD_CPU_PARAMETER,ReadCPUparameter) // error here
Run Code Online (Sandbox Code Playgroud)
(这个不是我写的。我需要在Win7机器上从Win2000重新编译一个旧项目。旧的VS6.0项目 -> VS2010 Prof.)
代码:
// class CStartup : public CDialog {};
#include "stdafx.h"
#include "MU.h"
#include "Startup.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CStartup::CStartup(CWnd* pParent /*=NULL*/) : CDialog(CStartup::IDD, pParent)
{
p_p = &cpu_par;
}
void CStartup::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CStartup, CDialog)
ON_WM_SHOWWINDOW()
ON_MESSAGE(WM_UPLOAD_CPU_PARAMETER,ReadCPUparameter) // error here
END_MESSAGE_MAP()
const int nLanguageIds_Language[] =
{
// ...
};
#define MAX_READINGS 200
BOOL CStartup::OnInitDialog()
{
// ...
}
void CStartup::OnOK()
{
CDialog::OnOK();
}
int CStartup::Check_OnRead()
{
// ...
}
void CStartup::ReadCPUparameter()
{
// ...
}
void CStartup::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
PostMessage( WM_UPLOAD_CPU_PARAMETER );
}
Run Code Online (Sandbox Code Playgroud)
宏背后的代码ON_MESSAGE期望ReadCPUparameter具有以下签名:
'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'.由于实际签名不同,它抱怨两个函数指针的类型不兼容。这就像将 a 传递struct Oranges*给需要 a 的函数一样struct Apples*。
我猜CDialog继承自CWND,因此您只需将函数签名更改为
LRESULT Startup::ReadCPUparameter(WPARAM wparam, LPARAM lparam);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2560 次 |
| 最近记录: |