Solved

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'

Posted on 2006-06-09
9
1,136 Views
Last Modified: 2013-11-20
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(CEngOLCDlgBLAmbTemp, CDialog)
      //{{AFX_MSG_MAP(CEngOLCDlgBLAmbTemp)
      ON_BN_CLICKED(IDOK, OnBLOK)
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()


The compiler error is as follows:

1>c:\envdev-studio2005\envdevelopment-v1.87-vs2005\projects\msat-eol\main\dialogs\engolcdlgblambtemp.cpp(90) : 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.
0
Comment
Question by:ToshiShinohara
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 16873538
Does it work when you change your function from 'BOOL' to 'void' as the return type?
0
 

Author Comment

by:ToshiShinohara
ID: 16873678
Yes it does and I have other methods with void that don't give error.
0
 
LVL 86

Expert Comment

by:jkr
ID: 16873766
Well, the reason is that AFX_PMSG is typedef'd as

typedef void (AFX_MSG_CALL CCmdTarget::*AFX_PMSG)(void);

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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ToshiShinohara
ID: 16873867
Is there any way to get around and define a some return type ?
0
 
LVL 86

Expert Comment

by:jkr
ID: 16874095
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.
0
 

Author Comment

by:ToshiShinohara
ID: 16874256
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);
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 16875715
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
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 250 total points
ID: 16875772
You cannot change message handler prototypes because they are called by MFC Framework. Button message handler has void return type. Changing return type can corrupt the stack. Your old program works, but has hidden bug.
0
 

Author Comment

by:ToshiShinohara
ID: 16877678
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
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Separate files macro - Errors on larger data set 18 73
Whole sheet autoscrub still needed 19 53
How to know only "File created" with EventLog 3 35
zeroMAx challenge 20 125
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question