INFO: Do Not Forward DDEML Messages from a Hook Procedure (89828)



The information in this article applies to:

  • Microsoft Windows Software Development Kit (SDK) 3.1
  • Microsoft Win32 Application Programming Interface (API), when used with:
    • the operating system: Microsoft Windows NT 3.5
    • the operating system: Microsoft Windows NT 3.51
    • Microsoft Windows 95

This article was previously published under Q89828

SUMMARY

If an application for Windows uses the Dynamic Data Exchange Management Library (DDEML) in addition to a message hook [for example, by calling SetWindowsHook() or SetWindowsHookEx()], it is possible that your hook procedure will receive messages that are intended for the DDEML libraries.

For the DDEML libraries to work properly, you must make sure that your hook function does not forward on any messages that are intended for the DDEML libraries.

MORE INFORMATION

If your hook procedure receives a code of type MSGF_DDEMGR, you should return FALSE instead of calling the CallNextHookEx() function.

Use the following code to handle this situation:
   // This needs to be defined if you haven't already.
   #ifndef MSGF_DDEMGR
   #define MSGF_DDEMGR             0x8001
   #endif

   if (MSGF_DDEMGR == code)
      return FALSE;
   else
   {
   ...
   }
				
In cases where the callback function processes the message, it should return TRUE.

Note, however, how the message filter function is called from within DDEML:
   while (TimeOutHasntExpired) {
       GetMesage (&msg, (HWND)NULL, 0, 0);
       if ( !CallMsgFilter (&msg, MSGF_DDEMGR))
            DispatchMessage (&msg);
    }
				
Given this, a callback function that just returns would cause the CallMsgFilter() call above to return TRUE, and never dispatch the message. This inevitably causes an infinite loop in the application, because GetMessage() ends up retrieving the same message over and over, without dispatching it to the appropriate window for processing.

Therefore, a callback function that processes the message may not just return TRUE, but should also translate and dispatch messages appropriately.

The Windows 3.1 SDK's DDEMLCL sample demonstrates how to do this correctly in its MessageFilterProc() found in DDEMLCL.C:
   if (nCode == MSGF_DDEMGR) {

   /*
   * If a keyboard message is for MDI, let MDI client take care of it.
   * Otherwise, check to see if it is a normal accelerator key.
   * Otherwise, just handle the message as usual.
   */ 

       if ( !TranslateMDISysAccel (hWndMDIClient, lpmsg) &&
             !TranslateAccelerator (hWndFrame, hAccel, lpmsg))  {
             TranslateMessage (lpmsg);
             DispatchMessage (lpmsg);
         }
        return 1;
    }
				
For more information about message hooks and DDEML, please see the above mentioned functions in the Windows SDK manual or the online help facility.

Modification Type:MajorLast Reviewed:4/12/2004
Keywords:kbDDE kbinfo KB89828