Results 1 to 2 of 2

Thread: [RESOLVED] WH_CBT Hook (local) causes GPF?

  1. #1
    MerrionComputin
    Guest

    Resolved [RESOLVED] WH_CBT Hook (local) causes GPF?

    Hi,

    I have written a WH_CBT hook handling code and it works OK except for where Code = WHCBT_SYSCOMMAND...which causes a GPF.

    The code (snippet) is ...
    Code:
    Case HOOKPROC_CBT '<--CBT Hook is triggered
        Code = Arguments(1)
        wParam = Arguments(2)
        lParam = Arguments(3)
        Select Case Code '<--What type of message?
        '....
        Case     Case Code = HCBT_SYSCOMMAND
            Dim ptMouse As New APIPoint
            Dim activeBy As SystemCommandActivationMethods
            Select Case APIDispenser.HiWord(lParam)
            Case 0
                activeBy = SCAM_BYMNEMONIC
            Case -1
                activeBy = SCAM_BYSYSACCELERATOR
            Case Else
                activeBy = SCAM_BYMOUSE
                ptMouse.y = APIDispenser.HiWord(lParam)
                ptMouse.x = APIDispenser.LoWord(lParam)
            End Select
            '\ Only the upper 3 bytes are used - the lower 4 are reserved for the system...
            wParam = (wParam And &HFFF0)
            Select Case wParam
            Case SC_HOTKEY
                '\ A window is being activated by a hotkey
                wndThis.hWnd = lParam
                RaiseEvent ActivateWindowByHotkey(wndThis, Cancel)
            Case SC_TASKLIST
                RaiseEvent StartMenu(activeBy, ptMouse, Cancel)
            Case SC_MONITORPOWER
                If lParam = 1 Then
                    RaiseEvent MonitorLowPower(activeBy, ptMouse, Cancel)
                ElseIf lParam = 2 Then
                    RaiseEvent MonitorPowerOff(activeBy, ptMouse, Cancel)
                End If
            Case SC_CONTEXTHELP
                RaiseEvent InitiateContextHelp(activeBy, ptMouse, Cancel)
            '.......
            End Select
            If Cancel Then
                Arguments(4) = 1
            End If
         '.......
    Does anybody have any experience of this hook proc that could guide me to finding the source of the GPF?

    Many many many thanks in advance,
    Duncan

  2. #2
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148
    Aha - in the CBT proc (or any hook proc for that matter) if code is less that 0 pass it on with CallNextHookEx and return the result...and do nothing else.

    The new version H is fixed to do CBT hooks thus:

    Code:
    Option Explicit
    
    Dim WitheEvents vbLink As EventVB.ApiFunctions
    
    Dim WithEvents vbHook As EventVB.ApiSystemHook
    
    Private Sub Form_Load()
    
    Set vbLink = New ApiFunctions
    Set vbHook = vbLink.System.Hooks
    
    vbHook.StartHook WH_CBT, HOOK_PROCESS_LOCAL
    
    End Sub
    Thanks ,
    Duncan

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