Results 1 to 4 of 4
  1. #1
    Join Date
    May 2007
    Posts
    74

    Unanswered: SetWindowsHookEx: Crashing Access faster than a speeding bullet ...

    I'm running into a problem not long after the following line of code executes:

    Code:
    lHook = SetWindowsHookEx(WH_CALLWNDPROC, AddressOf HookWindow, MyHwnd, MyThreadID)
    Basically, Access 2003 terminates viciously - The entire application disappears completely. Nothing is even left in the Task Manager.

    I have read that the SetWindowsHookEx library call installs a hook procedure that intercepts messages before they get to the destination window.

    When I run the code in a more limited environment, everything works fine and my target window gets modified as expected. However, when I drag the same code into my more complex environment with tons o' tabs, buttons, and subforms, Access dies a sudden (though hopefully painless) death.

    Any ideas on what may be happening?

    azjazz
    Last edited by azjazz; 06-05-07 at 20:56.

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    It would be helpful to see what the function/sub SetWindowsHookEx looks like
    George
    Home | Blog

  3. #3
    Join Date
    May 2007
    Posts
    74
    The SetWindowsHookEx prototype looks like this:

    HHOOK SetWindowsHookEx(
    int idHook,
    HOOKPROC lpfn,
    HINSTANCE hMod,
    DWORD dwThreadId
    );

    SetWindowsHookEx comes from Microsoft's user32 library.

    You can read more about it here: SetWindowsHookEx MSDN Reference Material

    azjazz

  4. #4
    Join Date
    May 2007
    Posts
    74
    I found the solution.

    The problem was with the "Declare Function SendMessage" declaration(s) that I had in my code.

    The code I imported that was using the SetWindowsHookEx function had a different (and the correct) prototype for SendMessage. My old code had a different (and incorrect) prototype for SendMessage that wasn't being used previously.

    Not knowing this, I had used the older incorrect prototype, and had commented out the newer correct prototype.

    Once I saw the difference, and enabled the newer SendMessage prototype, everything is working fine.

    Cheers!

    azjazz

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •