FIX: Bad POINT Structure in MSG Returned by GetCurrentMessage

Last reviewed: September 18, 1997
Article ID: Q135913
2.00 2.10 WINDOWS NT kbprg kbbuglist kbfixlist

The information in this article applies to:

  • The Microsoft Foundation Classes(MFC) included with: Microsoft Visual C++, 32-bit Edition, versions 2.0, 2.1

SYMPTOMS

MFC provides a function called GetCurrentMessage that returns a pointer to a MSG structure encapsulating the current message being processed. The MSG structure contains a member variable (pt), of type POINT that contains incorrect values.

CAUSE

The GetCurrentMessage function fills in the POINT structure with the following line of code:

   *((DWORD*)&pThreadState->m_lastSentMsg.pt) = ::GetMessagePos();

This code was correct in the 16-bit version of Visual C++ because a POINT structure was made up of two intergers (int) that were each 16-bits. Thus the size of a POINT was the same as a DWORD.

However, in the 32-bit version of Windows and of the Visual C++ compiler, a POINT structure is made up of two LONGs, each 32-bits, so the total size of a POINT is now 64-bits and the above assignment is not valid.

RESOLUTION

To obtain the correct value for the point in the current MSG you can use MFC's overridden CPoint constructor which takes a DWORD as an argument. For example:

   CPoint pt(::GetMessagePos());
   // Now pt has the correct values

Please note that because the GetCurrentMessage function returns a pointer to a 'const' MSG structure, you can't change the pt member of the message structure.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem was corrected in Visual C++ version 2.2.


Additional reference words: 2.00 2.10 3.00 3.10
KBCategory: kbprg kbbuglist kbfixlist
KBSubcategory: MfcMisc
Technology : kbMfc
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.