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,138 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Looking for a specific application/software 2 124
Line meaning 9 97
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 625
mapAB Challlenge 35 182
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.

734 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