Click here to Skip to main content
15,867,851 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
(using Visual Studio 2012, same behaviour with VS2015)

I wanted to do a simple 64 bit MFC dialog application with a simple WM_MESSAGE handler.

This is what I did.

1. Open VS2012
2. Create new MFC dialog based application. (default is 32bit)
3. Add my message handler code (WM_MESSAGE and handler code)
4. Compile: All OK.
5. Add new x64 configuration (from base win32)
6. Compile: Compilation error on WM_MESSAGE

C++
1>------ Build started: Project: MFCApplication1, Configuration: Release x64 ------
1>  MFCApplication1Dlg.cpp
1>MFCApplication1Dlg.cpp(66): error C2440: 'static_cast' : cannot convert from 'HRESULT (__cdecl CMFCApplication1Dlg::* )(WPARAM,LPARAM)' to 'LRESULT (__cdecl CWnd::* )(WPARAM,LPARAM)'
1>          None of the functions with this name in scope match the target type


The related code:

C++
BEGIN_MESSAGE_MAP(CMFCApplication1Dlg, CDialogEx)
...
	ON_MESSAGE(WM_MY_MESSAGE, MyMessageHandle )
END_MESSAGE_MAP()


C++
class CMFCApplication1Dlg : public CDialogEx
{
//...
	HRESULT MyMessageHandle(WPARAM wParam, LPARAM lParam );
//...
};


C++
HRESULT CMFCApplication1Dlg::MyMessageHandle(WPARAM wParam, LPARAM lParam )
{
	return 0;
}


Handler signature seems to be OK. ( HRESULT f(WPARAM, LPARAM) ), Message Map looks ok.

There are tons of messages like that on the internets, but they all related to having a bad handler prototype (usually from porting from an older Visual Studio).

Any idea that I might have overlooked ?

I'm kind of stumped.

Thanks.
Max.
Posted

1 solution

As far as I know, HRESULT and LRESULT are different on a 64-bit system (LRESULT being wider). You have to use LRESULT in your message handler.

You may test yourself, try
C++
ASSERT(sizeof(HRESULT) == sizeof(LRESULT));


on both configurations (after removing your message handler from the 64 bit one, in order to make it compile :-) ).
 
Share this answer
 
v2
Comments
Maximilien 17-Aug-15 15:39pm    
Oh crap!!! I don't deserve to be in front of a computer today ... Thanks!!!
CPallini 17-Aug-15 15:56pm    
You are welcome. :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900