ToshiShinohara
asked on
compiler error while converting vs c++6 project to vs c++ 2005 ... error error C2440: 'static_cast' : cannot convert from 'BOOL’ to to 'AFX_PMSG'
This question is related with MFC code that compiles on VS C++6 and now converting to VS C++ 2005.
In my Dialog box
class CEngOLCDlgBLAmbTemp : public CDialog
I have button and when user clicks button, its message IDOK for ON_BN_CLICKED is captured in the code using method OnBLOK. I do some error checking and then decide wheather to close the dialog box or not.
The methods OnBLOK returns BOOL.
afx_msg BOOL OnBLOK();
BEGIN_MESSAGE_MAP(CEngOLCD lgBLAmbTem p, CDialog)
//{{AFX_MSG_MAP(CEngOLCDlg BLAmbTemp)
ON_BN_CLICKED(IDOK, OnBLOK)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
The compiler error is as follows:
1>c:\envdev-studio2005\env developmen t-v1.87-vs 2005\proje cts\msat-e ol\main\di alogs\engo lcdlgblamb temp.cpp(9 0) : error C2440: 'static_cast' : cannot convert from 'BOOL (__thiscall CEngOLCDlgBLAmbTemp::* )(void)' to 'AFX_PMSG'
1> None of the functions with this name in scope match the target type
I am using Studio 2005 first time and just trying to get the code to compile.
Any help is appreciated.
In my Dialog box
class CEngOLCDlgBLAmbTemp : public CDialog
I have button and when user clicks button, its message IDOK for ON_BN_CLICKED is captured in the code using method OnBLOK. I do some error checking and then decide wheather to close the dialog box or not.
The methods OnBLOK returns BOOL.
afx_msg BOOL OnBLOK();
BEGIN_MESSAGE_MAP(CEngOLCD
//{{AFX_MSG_MAP(CEngOLCDlg
ON_BN_CLICKED(IDOK, OnBLOK)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
The compiler error is as follows:
1>c:\envdev-studio2005\env
1> None of the functions with this name in scope match the target type
I am using Studio 2005 first time and just trying to get the code to compile.
Any help is appreciated.
Does it work when you change your function from 'BOOL' to 'void' as the return type?
ASKER
Yes it does and I have other methods with void that don't give error.
Well, the reason is that AFX_PMSG is typedef'd as
typedef void (AFX_MSG_CALL CCmdTarget::*AFX_PMSG)(voi d);
i.e. as 'void' in afxwin.h. The new compiler is obviously stricter than VC6 and does not allow a different return type even though the signatures match.
typedef void (AFX_MSG_CALL CCmdTarget::*AFX_PMSG)(voi
i.e. as 'void' in afxwin.h. The new compiler is obviously stricter than VC6 and does not allow a different return type even though the signatures match.
ASKER
Is there any way to get around and define a some return type ?
All you need to do is changing the return type of the function(s) in question from 'BOOL' to 'void', then you should get rid of the error.
ASKER
I understand, but it breaks the funtionality of program.
I am not sure how come std. MFC method OnCtlColordoens't return void but compiles.
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
I am not sure how come std. MFC method OnCtlColordoens't return void but compiles.
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
What you need is something like
void CMyDlg::OnBtnClick()
{
TestSomething();
}
and
BOOL CMyDlg()
{
return TRUE;
}
separate the button action from the functionality that tests.
ps. OnCtlColor - that is defined to return a HBRUSH, that is why it compiles correctly in VS 2005
void CMyDlg::OnBtnClick()
{
TestSomething();
}
and
BOOL CMyDlg()
{
return TRUE;
}
separate the button action from the functionality that tests.
ps. OnCtlColor - that is defined to return a HBRUSH, that is why it compiles correctly in VS 2005
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you Andy and JKR. I really appreciate your advice from both of you.
By the way, do you know any MFC/C++ Free Lance Programmer in New York/New Jersey ( USA ) area, please conatct me at spjoshi@earthlink.net.
Regards
Santosh
By the way, do you know any MFC/C++ Free Lance Programmer in New York/New Jersey ( USA ) area, please conatct me at spjoshi@earthlink.net.
Regards
Santosh