CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2000
    Posts
    127

    UnhookWindowsHookEx

    Is there a way to check whether the API UnhookWindowsHookEx() is true ?


  2. #2
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: UnhookWindowsHookEx

    It returns the previous hook id (positive number) or zero on success. It sets Err.LastDLLError on failure.
    To decode the failure reason:

    '\\ -- [ LastSystemError ]------------------------------------------------------------------
    '\\ Returns the message from the system which describes the last dll error to occur, as
    '\\ held in Err.LastDllError. This function should be called as soon after the API call
    '\\ which might have errored, as this member can be reset to zero by subsequent API calls.
    '\\ ----------------------------------------------------------------------------------------
    '\\ You have a royalty free right to use, reproduce, modify, publish and mess with this code
    '\\ I'd like you to visit http://www.merrioncomputing.com for updates, but won't force you
    '\\ ----------------------------------------------------------------------------------------
    public Function LastSystemError() as string

    Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
    Dim sError as string * 500 '\\ Preinitilise a string buffer to put any error message into
    Dim lErrNum as Long
    Dim lErrMsg as Long

    lErrNum = Err.LastDllError

    lErrMsg = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, byval 0&, lErrNum, 0, sError, len(sError), 0)

    LastSystemError = Trim(sError)

    End Function




    and an example of how this is used...

    public Sub StopHook(byval HookType as enHookTypes)

    Dim lret as Long

    '\\ If a hook of this type is already set, unhook this first
    If HookIdByType(HookType) > 0 then
    lret = UnhookWindowsHookEx(HookIdByType(HookType))
    If Err.LastDllError > 0 then
    Call ReportError(Err.LastDllError, "EnumHandler:StopHook", APIDispenser.LastSystemError)
    End If
    End If

    End Sub




    HTH,
    Duncan

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  3. #3
    Join Date
    Sep 2000
    Posts
    127

    Re: UnhookWindowsHookEx

    Sorry if i did not make myself clear. Actually , i just want to detect see if this UnhookWindowsHookEx API has occurred . Do you have any suggestions on this ?


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured