|
-
January 13th, 2011, 03:57 PM
#1
Error when converting VC 6 project
I've been out of the VC world for years now. I'm trying to build an old project and I'm getting this error:
Code:
Error 2 error C2440: 'static_cast' : cannot convert from 'BOOL (__thiscall CMainFrame::* )(void)' to 'AFX_PMSG' d:\user\alin\vc++\xcp_diag v 1.0.0 beta4\mainfrm.cpp 99 1 XCP
Mainframe.cpp:
Code:
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_STOP_LOG, OnStopLog)
ON_COMMAND(ID_START_LOG, OnStartLog)
ON_UPDATE_COMMAND_UI(ID_START_LOG, OnUpdateStartLog)
ON_UPDATE_COMMAND_UI(ID_STOP_LOG, OnUpdateStopLog)
ON_COMMAND(ID_APP_SET_ADDR_INTEL, OnAppSetAddrIntel)
ON_COMMAND(ID_APP_SET_ADDR_MOT, OnAppSetAddrMotorola)
ON_UPDATE_COMMAND_UI(ID_APP_SET_ADDR_INTEL, OnUpdateAppSetAddrIntel)
ON_UPDATE_COMMAND_UI(ID_APP_SET_ADDR_MOT, OnUpdateAppSetAddrMotorola)
ON_WM_TIMER()
ON_WM_CLOSE()
ON_COMMAND(ID_FILE_SAVE_LOG, OnSaveLogFile) --> This is where the compiler reports the error.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
Mainframe.h:
Code:
afx_msg BOOL OnSaveLogFile();
Thanks,
Alin
-
January 13th, 2011, 04:17 PM
#2
Re: Error when converting VC 6 project
-
January 13th, 2011, 04:22 PM
#3
Re: Error when converting VC 6 project
I mean to remember that I had the same error some years ago when porting a VC6 project to VC8 (VS2005).
The ON_COMMAND macro tries to "cast" a function pointer of a member function of the current class to the signature the handler function of a WM_COMMAND message does require. If this fails in a later version of VC it could be either because the signature has changed in the meanwhile, i. e. the OnCommand handler needs now a different interface, or because the compiler wouldn't accept that kind of cast at all. The latter is less likely if you made sure that the ON_COMMAND macro comes from a header of the new compiler version and not from VC6, i. e. if you don't have a mixed environment.
If you could post the definition of the AFX_PMSG macro (press F12 on that macro) I probably would remember what I did to solve the issue.
-
January 13th, 2011, 04:22 PM
#4
Re: Error when converting VC 6 project
AFAIK, the message handler signature for ON_COMMAND macro is
Code:
afx_msg [B]void/B] OnSomething(void)[
*not* afx_msg BOOL ...
Victor Nijegorodov
-
January 13th, 2011, 04:23 PM
#5
Re: Error when converting VC 6 project
Oh, CodePlug did remember (google) faster than me
-
January 13th, 2011, 04:43 PM
#6
Re: Error when converting VC 6 project
thanks for the replies.
i still remember the ON_COMMAND signature is void ), but at the same time my function returns BOOL and i need it to be that way. is there a cast i could try to make it accept BOOL like afx_msg BOOL OnSaveLogFile()?
-
January 13th, 2011, 05:26 PM
#7
Re: Error when converting VC 6 project
Hi Alin,
 Originally Posted by Alin
is there a cast i could try to make it accept BOOL like afx_msg BOOL OnSaveLogFile()?
Nope. Not good. No way.
MSDN
WM_COMMAND Message
Return Value
If an application processes this message, it should return zero.
And that MFC does.
However, if really makes sense for you to return other value, use ON_MESSAGE macro instead.
Although I'm wondering if something like that has any sense or effect.
Last edited by ovidiucucu; January 13th, 2011 at 05:34 PM.
-
January 13th, 2011, 06:39 PM
#8
Re: Error when converting VC 6 project
Code:
afx_msg void MMOnSaveLogFile() {OnSaveLogFile();}
Use that in your message map.
gg
-
January 14th, 2011, 11:20 AM
#9
Re: Error when converting VC 6 project
 Originally Posted by Codeplug
Code:
afx_msg void MMOnSaveLogFile() {OnSaveLogFile();}
Use that in your message map.
gg
That did the trick, thanks very much.
-
January 14th, 2011, 11:46 AM
#10
Re: Error when converting VC 6 project
my function returns BOOL and i need it to be that way
A BOOL return in a message map function is senseful if there is a default handling which you can invoke by returning FALSE what means "not handled". As MS did change the signature for OnCommand handlers you can be sure there is no default handling. Hence returning a BOOL or not makes no difference. So I would change the signature of my handler function in order to have a correct interface and remove the return statements accordingly.
If you need a BOOL return cause you need to call the function from another function, you better rename the old function to 'SaveLogFile' and call the void function OnSaveLogFile.
-
January 14th, 2011, 12:09 PM
#11
Re: Error when converting VC 6 project
 Originally Posted by Alin
That did the trick, thanks very much.
Still wondering. Has it any effect, or it's only to compile?
-
January 14th, 2011, 01:44 PM
#12
Re: Error when converting VC 6 project
 Originally Posted by ovidiucucu
Still wondering. Has it any effect, or it's only to compile?
In VC8 help they described ON_COMMAND_EX with
An extended form of command message handlers is available for advanced uses. The ON_COMMAND_EX macro is used for such message handlers, and it provides a superset of the ON_COMMAND functionality. Extended command-handler member functions take a single parameter, a UINT containing the command ID, and return a BOOL
So it looks as ON_COMMAND_EX has now the functionality of former ON_COMMAND and that newer ON_COMMAND only will accept a void handler.
-
January 14th, 2011, 01:57 PM
#13
Re: Error when converting VC 6 project
 Originally Posted by itsmeandnobodyelse
In VC8 help they described ON_COMMAND_EX with
...
So it looks as ON_COMMAND_EX has now the functionality of former ON_COMMAND and that newer ON_COMMAND only will accept a void handler.
This ON_COMMAND_EX looks like the old ON_CONTROL_REFLECT macro. Doesn't it?
Victor Nijegorodov
-
January 14th, 2011, 02:02 PM
#14
Re: Error when converting VC 6 project
Don't know exactly but I mean to remember that the _REFLECT macros were to redirect messages normally sent to the parent dialog to the (derived) control itself.
See here for details: http://msdn.microsoft.com/de-de/libr...(v=vs.80).aspx
-
January 14th, 2011, 02:52 PM
#15
Re: Error when converting VC 6 project
>> ... ON_COMMAND_EX has now the functionality of former ON_COMMAND and that newer ON_COMMAND only will accept a void handler.
http://msdn.microsoft.com/en-us/libr...8VS.60%29.aspx
They've both been the same since 6.0.
The original code compiled under 6.0 either because the conversion was forced or the compiler silently accepted it.
gg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|