2

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 ?

Error:

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

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

Code:

// 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 );     
}
Bitterblue
  • 13,162
  • 17
  • 86
  • 124
  • i think the error message exactly says that is wrong. so why not fixing the function signature to the expected signature. – vlad_tepesch Apr 04 '14 at 11:16
  • @vlad_tepesch Can you point me to the function you mean ? And please read the 2nd paragraph of the question. I'm not that familiar with C++ errors. – Bitterblue Apr 04 '14 at 11:21

1 Answers1

5

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);
vlad_tepesch
  • 6,681
  • 1
  • 38
  • 80
  • You could have also tell me that `ON_MESSAGE` is inbuild macro that registers my functions to windows messages. That was one thing I didn't know. Thanks anyways! I solved 2 of those errors and I understand it better now. The project actually compiled. ^^ – Bitterblue Apr 04 '14 at 11:47
  • @mini-me i do not know anything about that MFC stuff. I just read (and understood) the compiler error message. – vlad_tepesch Apr 04 '14 at 11:49
  • vlad explained the problem nicely. The reason it happened is that the VS6 compiler was not smart enough to detect the error. – ScottMcP-MVP Apr 04 '14 at 12:09
  • @ScottMcP-MVP i cannot believe that this does not trigger crashes. in thiscall the callee cleans the stack, so the the caller puts things on stack (wparam, lparam) and the callee does not clean them since it is defined as `void (CWND::*)(void)` so the stack of caller should be corrupted. or did i miss something? Same thing with return value. the caller will evaluate them and the callee leavs random values in them. – vlad_tepesch Apr 04 '14 at 12:19