PRB: DLL System Hook Function Not Affecting Apps System-Wide

Last reviewed: July 23, 1997
Article ID: Q88190
3.10 WINDOWS kbprg kbprb

The information in this article applies to:

  • Microsoft Windows Software Development Kit (SDK) for Windows version 3.1

SYMPTOMS

When you are trying to install a system hook function with SetWindowsHookEx in a dynamic-link library (DLL), the hook function is executed only within the calling application even though it is supposed to affect all applications system-wide.

CAUSE

In Windows 3.0, the minimum required compile option to generate the appropriate entry/exit code sequence for a Windows-based application is the /Gw switch.

With Microsoft C/C++ version 7.0, however, the documentation states that the /Gw and /GW switches should be used only for applications that must run in real mode Windows. Because real mode is no longer available in Windows 3.1, most programs should now be built using the /GA switch (/GD for DLLs). The C 7.0 /GA and /GD switches require that exported functions (especially callback functions) be explicitly marked as __export if the switch is to affect them.

RESOLUTION

If the DLL containing the hook function is compiled with the /GD switch, the hook function should be explicitly marked with the __export keyword:

   LRESULT FAR PASCAL __export CbtFunc (int Code,
                                        WPARAM wParam, LPARAM lParam);


Additional reference words: 3.10
KBCategory: kbprg kbprb
KBSubcategory: UsrHks
Keywords : kb16bitonly


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: July 23, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.