58953

Casting error in C++

Question:

Can someone help me with this error ? I'm C++ newbie. And it seems the error occurs right in a bunch of macros. What can I do to solve it ? Or how can I track it down to the source ?

I don't really understand the error. Does it mean the compiler tried to convert the method void ReadCPUparameter() to a LRESULT funcName(WPARAM wParam, LPARAM lParam) function header ?

<strong>Error:</strong>

// 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 <hr />

<em>(I didn't write this. I need to recompile an old project from Win2000 on a Win7 machine. Old VS6.0 project -> VS2010 Prof.)</em>

<strong>Code:</strong>

// 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 ); }

Answer1:

the code behind the ON_MESSAGE macro expected ReadCPUparameterto have the following signature: 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'. since the actual signature differs it complain about type incompatibility of the two function pointers. Its like passing a struct Oranges* to a function that expects a struct Apples*.

I guess CDialog inherits from CWND, so all you have to do to change your function signature to

LRESULT Startup::ReadCPUparameter(WPARAM wparam, LPARAM lparam);

Recommend

  • Updating CMFCRibbonBar elements from document
  • Casting error in C++
  • MFC Application getting stuck when adding list control elements [closed]
  • How to choose the right buffer to draw and stop it from swapping continuously
  • How to make bot respond to a certain msg?
  • What involves to schedule a thread in Windows?
  • c++ Template error in main function?
  • Discord.py --> channel.mention
  • (ERROR MODULE) python mqtt_Listen_Sensor_Data.py
  • Resurrecting MFC/Visual Studio 6.0 project in VS2010
  • How to detect whether a control is standard or active-x control?
  • Not a valid Win32 application… Python, PyInstaller, Windows7
  • Why does VB.NET Jet 4.0 app crash if Office not installed?
  • ShowDuration attribute cannot resolve in tooltip at silverlight 4
  • MonoDroid - setting background color from colors.xml throws InvalidOperationException
  • Cannot open include file :'stddef.h' No such file or directory found error when creating a
  • JSP compilation error on Generics
  • Visual Studio 2010 Extensibility - Override Build Action without effecting cproj file
  • Add Windows Feature from C#
  • Graphics.CopyFromScreen [Web application] + The handle is invalid
  • Jenkins: FATAL: Could not initialize class hudson.util.ProcessTree$UnixReflection
  • ADO and msqli connections very slow
  • Switching to Release Build causes runtime error in Web Reference
  • javaw.exe and eclipse startup problems
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • QuartzCore.framework for Mono Develop
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?