ON_WM_NCHITTEST (and other MFC macros) won't compile in whidbey

1>.\sizecbar\scbarg.cpp(59) : error C2440: 'static_cast' : cannot convert from 'UINT (__thiscall CSizingControlBarG::* )(CPoint)' to 'LRESULT (__thiscall CWnd::* )(CPoint)'
1>        Cast from base to derived requires dynamic_cast or static_cast


FYI, ON_WM_NCHITTEST looks like this:


#define ON_WM_NCHITTEST() \
    { WM_NCHITTEST, 0, 0, 0, AfxSig_l_p, \
        (AFX_PMSG)(AFX_PMSGW) \
        (static_cast< LRESULT (AFX_MSG_CALL CWnd::*)(CPoint) > (&ThisClass :: OnNcHitTest)) },


I don't even understand the error because as far as I can tell, it's casting to base, not to derived and it is using static_cast.

Solution or workaround

PS When are we going to get code formatting in this forum


Answer this question

ON_WM_NCHITTEST (and other MFC macros) won't compile in whidbey

  • Martin Bushnell

    Does anyone happen to know if this has changed post beta 2 Can someone with the June CTP or later check if it's back to UINT Or is it still LRESULT
  • portugal1234

     Ted. wrote:

    Hi Microsoft, why exactly was the return value changed from UINT to LRESULT.  I've seen bugs that were placed on the product feedback center relating to the fact that the class wizard no longer matches, but the question remains, why was this changed   It forces me to have two separate definitions depending on whether I'm building against 2003 vs. 2005.



    Hi Ted,

    We have changed return type of OnNcHitTest because some of return values can be negative, for example HTERROR. The correct return type is LRESULT, and as I see in June CTP, wizards already generate the correct prototype for this method. It was one of the breaking change made in VS2005 because of significant number of customers complaining about UINT being a type of a return value.

    Thanks,
    Nikola
    VC++

  • rob kraft

    This seems like a noob question but how could i determine whether the code is being compiled by Visual Studio .Net or Visual Studio 2005   Is there a preprocessor directive
  • ray_ch

    Installed Beta2...

    The documentation still states it's
    afx_msg UINT OnNcHitTest(CPoint point );

    But LRESULT is in the MFC sources. And old code won't compile.


  • Alphi

     Unjedai wrote:
    how could i determine whether the code is being compiled by Visual Studio .Net or Visual Studio 2005   Is there a preprocessor directive


    Yes, you can use _MSC_VER >= 1400

    For example,


    #if _MSC_VER >= 1400
     afx_msg LRESULT OnNcHitTest(CPoint point);
    #else
     afx_msg UINT OnNcHitTest(CPoint point);
    #endif 

  • Fabriciom

    Hi Microsoft, why exactly was the return value changed from UINT to LRESULT.  I've seen bugs that were placed on the product feedback center relating to the fact that the class wizard no longer matches, but the question remains, why was this changed   It forces me to have two separate definitions depending on whether I'm building against 2003 vs. 2005.


  • Ziper

     jedediah wrote:
    The problem was that the method was declared with a UINT return type rather than LRESULT. For some reason, this worked in VC2003 but not in whidbey.

    Yes, I encounterd the same problem. When I changed UINT to LRESULT manually, it compiled ok. But I added the message handler by class property.
    So, can we say this is a bug of whidbey

  • Jim R

    makes sense - thanks!

  • Don Barber at WellCare

    The problem was that the method was declared with a UINT return type rather than LRESULT. For some reason, this worked in VC2003 but not in whidbey.

  • ON_WM_NCHITTEST (and other MFC macros) won't compile in whidbey