3

I am converting my project from a 32 bit version to 64 bit version, when compiling the project in 64 bit, i get the below error.

Error   2   error C2440: 'static_cast' : cannot convert from 'long (__cdecl BrnDefDlgClass::* )(UINT,long)' to 'LRESULT (__cdecl CWnd::* )(WPARAM,LPARAM)'  C:\Program Files (x86)\...\CXX\TEST.CXX 854 1   cfg

this error points me to below line of code.

ON_MESSAGE        (WM_USER_AFTERCBNSELCHANGE,   OnAfterCBSelectMsg)

advice please why would this error occur.

Thanks

ARV
  • 1,111
  • 5
  • 22
  • 46

2 Answers2

7

I suggest you look at the definition of OnAfterCBSelectMsg and modify it to use LRESULT as return type, and WPARAM and LPARAM as parameters (just as the second signature in your error message).

LRESULT is defined as LONG_PTR, and whenever PTR appears in a name, you should expect it to be large enough to hold a pointer. Pointers are 4 bytes on 32 Bit and 8 bytes on 64 bit, so an LRESULT won't fit into a long (which is 4 bytes) if you compile for 64 bit.

Using WPARAM and LPARAM as parameter types is also important, as their size changes depending on the platform, too. See the answers to this question for more info: What are the definitions for LPARAM and WPARAM?

Community
  • 1
  • 1
Botz3000
  • 39,020
  • 8
  • 103
  • 127
2

WPARAM is defined as unsigned __int64, LRESULT and LPARAM are __int64 in 64-bit Windows.

You have to change the signature of BrnDefDlgClass accordingly. If the WinAPI-provided typedefs were used instead of built-in types, it would be compilable on both 32 and 64-bit platforms.

Andriy
  • 8,486
  • 3
  • 27
  • 51