Subclassing & Hooking with Visual Basic By Stephen Teilhet Unconfirmed error reports are from readers. They have not yet been approved or disproved by the author or editor and represent solely the opinion of the reader. This page was updated July 16, 2004 Here's a key to the markup: [page-number]: serious technical mistake {page-number}: minor technical mistake : important language/formatting problem (page-number): language change or minor formatting problem ?page-number?: reader question or request for clarification UNCONFIRMED errors and comments from readers: ?89? 1st paragraph; When you say "... we need to start a new thread in the DLL and use this thread to execute the DLLFunct function code": 1) How do you start another thread in a DLL? 2) How do you know when it done processing in the Main program? 3) Can you give a short example? [95] Example 4-1; The Class_Initialize event has the line of code "m_lOrigClass = 0" but on the previous page, 94, this variable is not defined. I believe it should be "m_lOrigWndProc =0" {101} 1st paragraph; You have the line of code: Dim CSubClsApp As CSubClass if you want to use CSubClsApp outside of the .bas, i.e. in your form, it must be: Public CSubClsApp As CSubClass [102] Example 4-5; In the example code, the line in the book is: NewWndProc = CallWindowProc(CSubClsApp.OrigWndProc, hwnd, uMsg, wParam, lParam) but on p.94 you tell us to name the class CSubClass. So the line should read: NewWndProc = CallWindowProc(CSubClass.OrigWndProc, hwnd, uMsg, wParam, lParam) [109] Example 4.8; The first If statement : If uMsg = WM_SIZING and wParam <> WMSZ_BOTTOM Then should this not be :- If uMsg = WM_SIZING and (wParam <> WMSZ_BOTTOM) Then caue if you change the wParam check to WMSZ_TOP it doesn't work with the given example. [140] At the bottom, example 5-1; When I built this simple example, it didn't work ! The program returned immediately from the call to the API function "GetSaveFileName" with an error lRetVal=0 , without showing anything first. I use VB6 SP5, Windows98 I spend two days looking for the solution to the problem. At last I found (in MSDN) that apparently the trhee last items in the type declaration of OpenFilename are not supported under Windows98 (or Windows95), and should be commented out. When I did that, everything worked as promised. (356) bottom and middle of page; There are two: 1. Middle of page: typedef struct tagMOUSEHOOKSTRUCT was already defined in the #include "WINUSER.H" file in the "MainHook.cpp". Visual c++ 6 pukes on this one. The removal of the struct definition in the "MainHook.h" fixes that problem 2. Bottom of Page: "HANDLEhInstance" SHOULD BE "HANDLE hInstance" and "HHOOKhhookHooks" SHOULD BE "HHOOK hhookHooks" The print history on page 2 = June 2001 [466] Example 20-1; The JournalPlaybackProc shown here does not work. When I ran this program, it would play back the macro at lightning speed, which tells me that the delay was not happening. If you look at the code, the delay time is being set as the return value when uCode = HC_GETNEXT, however, the function does not exit. It falls through to the call to CallNextHookEx(). Why set it if you don't return? I did some searching on the Microsoft site and found their example of JournalPlaybackProc. From there I discovered what I needed to change. Add a static boolean called fDelay. Change the code for setting the return value to the following: If fDelay Then fDelay = False JournalPlaybackProc = lParam.time Exit Function End If Then under uCode = HC_SKIP, add the following line: fDelay = True Now things play back at the speed that I would expect.