A Conversation for The H2G2 Programmers' Corner

Windopws Hook help - WH_CBT

Post 1

Is mise Duncan

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 ...

'--8<---------------------------------------------------------------
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
'.......
'--8<--------------------------------------------------------------

Does anybody have any experience of this hook proc that could guide me to finding the source of the GPF?


Windows Hook help - WH_CBT [Resoved]

Post 2

Is mise Duncan

It should have been:

wParam = (wParam Or &HFFFFF0000)

smiley - smiley


Windows Hook help - WH_CBT [Resoved]

Post 3

DoctorMO (Keeper of the Computer, Guru, Community Artist)

What does it do?

-- DoctorMO --


Windows Hook help - WH_CBT [Resoved]

Post 4

Is mise Duncan

The WH_CBT hook is called whenever one of a number of events that is of use to a computer based training application occurs. For example, when a new window is created, when the user switches between windows, when the screensaver kicks in etc.
However I am using it to write a remote monitoring/debugging tool for one of the work apps we use here. The idea is that the hook (and a WH_JOURNALRECORD hook) will record what the user is doing in the app and save this as a log file. Then the developer can play back this log in the development environment and (hopefully) reproduce whatever behaviour the user was reporting.
The WH_JOURNALRECORD hook was quite easy, but the CBT one is giving me lots of grief...and the documentation is a bit sparce smiley - sadface


Windows Hook help - WH_CBT [Resoved]

Post 5

DoctorMO (Keeper of the Computer, Guru, Community Artist)

Looks like fun, would you beable to have Remote access Via the hooks?

-- DoctorMO --


Windows Hook help - WH_CBT [Resoved]

Post 6

Is mise Duncan

You can connect the hooks via TCP/IP on WinSock (or network protocol of choice) but the software must be installed on client and server - you couldn't spy on someone without their knowing it. Also hooks involve a performance hit - it is best to use them sparingly....


Windows Hook help - WH_CBT [Resoved]

Post 7

DoctorMO (Keeper of the Computer, Guru, Community Artist)

Ah,

--DoctorMO --


Windows Hook help - WH_CBT [Resoved]

Post 8

Is mise Duncan

Ah indeed...
*goes to get another whisky..*


Windows Hook help - WH_CBT [Resoved]

Post 9

DoctorMO (Keeper of the Computer, Guru, Community Artist)

Wounder if you could do the same in Linux??

-- DoctorMO --


Windows Hook help - WH_CBT [Resoved]

Post 10

Is mise Duncan

I'm not to knowledgeable about Linux..., but the new EventVB version H is fixed to do CBT hooks..

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


Windows Hook help - WH_CBT [Resoved]

Post 11

DoctorMO (Keeper of the Computer, Guru, Community Artist)

Looks alot easier, but whats this New VB?

-- DoctorMO --


Windows Hook help - WH_CBT [Resoved]

Post 12

Is mise Duncan

Not new VB - a DLL wot I wrote to make this API stuff a bit easier. Bit of a moot point though, as we're all going .Net now...

The dll is at http://www.merrioncomputing.com/EventVB/Release_H.htm fyi...


Windows Hook help - WH_CBT [Resoved]

Post 13

DoctorMO (Keeper of the Computer, Guru, Community Artist)

Ah I see, looks usefull, but yes .NET train is here and we'er all paying microsoft for the journey, coffe and window room. smiley - winkeye

-- DoctorMO --


Key: Complain about this post