Microsoft KB Archive/63123

INF: Sample PM Program That Creates a System Help Hook PSS ID Number: Q63123 Article last modified on 09-09-1991 PSS database name: P_PresMan

1.21

OS/2

Summary:

In the Software/Data Library is a program named HELPHOOK that demonstrates how to create a system help hook. HELPHOOK can be found in the Software/Data Library by searching on the filename, the Q number of this article, or S12614. HELPHOOK was archived using the PKware file-compression utility.

More Information:

All system help hooks are required to be in a DLL (dynamic-link library) to ensure that they can be shared among various processes.

HELPHOOK has several parts to it. First, there is the main program named BASE.EXE. This is a program that upon startup loads the DLL (titled “Help”), calls DosLoadModule to get the handle to the DLL, and then calls WinSetHook to create the help hook. In the call to WinSetHook, it is necessary to use the handle returned from DosLoadModule to ensure that the help function can be located in the DLL. If NULL is used for this parameter, the .EXE file will be searched. (Do not use NULL for system hooks because there is a DLL.)

The second part to HELPHOOK is the DLL code. HELP.C is the C code for the DLL. This is where the actual HelpHook function is located. HELP.DEF is the .DEF file for the DLL, and INIT.C is the assembly initialization code that must be used with DLLs. There is a makefile for the DLL called HELPDLL. Also, this makefile is included in the makefile for the BASE program. Therefore, if “MAKE BASE” is entered, the entire sample code will be automatically built.

For this sample, an import library is used; therefore, it is not necessary to worry about an IMPORT section in the main application’s .DEF file. Just be sure to include in the DLL’s .DEF file EXPORTS section all the functions in the DLL, and link in the import library to the application. After building the application, there will be an .EXE file (BASE.EXE) that is the main application, and a DLL (HELP.DLL) that must appear in the same directory as the .EXE file, or someplace on the LIBPATH search path.

Now, whenever a WM_HELP message is generated in the system, a message box will appear stating that the program is in the HelpHook function. The return value for the HelpHook function should be TRUE if the message should be passed on to the next help hook in the chain, or FALSE if the rest of the hooks should be skipped.

Be sure to release the handle to the DLL and the help hook before terminating the application.

For more information on this topic, please see the QuickHelp overview on help hooks. For information on creating DLLs, see Chapter 19 of Ray Duncan’s “Advanced OS/2 Programming” (Microsoft Press).

Copyright Microsoft Corporation 1991.