FIX: GP Fault from ON_REGISTERED_MESSAGE() in _USRDLL

Last reviewed: September 16, 1997
Article ID: Q99787

The information in this article applies to:
  • The Microsoft Foundation Classes (MFC), included with:

        - Microsoft Visual C++ for Windows, version 1.0
    

SYMPTOMS

In an application developed with the Microsoft Foundation Class Library, the ON_REGISTERED_MESSAGE() macro is used to process messages created with the RegisterWindowMessage() function. However, if a _USRDLL dynamic-link library (DLL) uses the ON_REGISTERED_MESSAGE() macro, the DLL generates a general protection (GP) fault when it processes the message.

CAUSE

In the WINCORE.CPP file, on line 851, pMessageMap is declared as follows:

   AFX_MSGMAP* pMessageMap;

AFX_MSGMAP is a NEAR structure. Consequently, pMessageMap is a NEAR pointer. Later in the WINCORE.CPP file, on line 914, the code uses the _AFX_FP_SEG() macro to determine the segment in which the message map is stored. Because pMessageMap is a NEAR pointer, _AFX_FP_SEG() gives an incorrect result.

RESOLUTION

Modify the DLL code to remove the ON_REGISTERED_MESSAGE() macro and add code that overrides WindowProc(). The WindowProc() function is called for each message a window receives. In WindowProc(), test the wMessage parameter to determine if it is the registered message and process the message when it arrives. Call the base class version of WindowProc() to dispatch other messages according to the message map.

STATUS

Microsoft has confirmed this to be a problem in the Microsoft Foundation Class Library version 2.0 for Windows. The problem was fixed and the ON_REGISTERED_MACRO now can be used in a USRDLL with version 2.5 of the Microsoft Foundation Classes.

MORE INFORMATION

The code example below demonstrates the method described above. The CMyWnd class is derived from CWnd.

   UINT nRegMessage; // contains result from RegisterWindowMessage()

   ...

   LRESULT CMyWnd::WindowProc(UINT message, WPARAM wParam,
      LPARAM lParam)
   {
      // If the message is the registered message,
      // call the handler for that message
      if (message == nRegMessage)
         return OnMyRegisteredMessage(wParam, lParam);

      // Otherwise, call the base class version
      // of WindowProc to process other messages
      CWnd::WindowProc(message, wParam, lParam);
   }
Keywords          : kb16bitonly MfcDLL
Technology        : kbmfc
Version           : 1.0
Platform          : WINDOWS
Issue type        : kbbug
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 16, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.