Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 423
  • Last Modified:

How to capture WM_CANCELJOURNAL message

Hi experts,
I have a 'System Hook' DLL that sets a hook for WH_GETMESSAGE and WH_JOURNALRECORD and all works OK with the exception of capturing WM_CANCELJOURNAL to stop the recording in my application by sending a special event (that I call CancelJournal in my code below).

I'm using Windows XP and when I press Ctrl Escape keys (simultaneously) the actual hook is deactivated in OS, because I output a message in the application status bar when events are coming in and following the Ctrl Escape the events stop coming. However, the GetMessageProc procedure doesn't seem to detect this activity and doesn't send the special (CancelJournal) event to my application so my application still thinks that the recording is on.

Below is the relevant code from the 'System Hook' DLL. I would appreciate any help on why the GetMessageProc doesn't detect WM_CANCELJOURNAL message.

Thanks a lot in advance,
     Michael

P.S. I've left aout all the Playback related code as that works OK.


CLASS CONTENTS
---------------------
Public Event RecordEvent(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long)
Public Event CancelJournal()


Public Function SetRecordHook(hInstance As Long, ThreadID As Long) As Boolean
    If hAppHook = 0 Then hAppHook = SetWindowsHookEx(WH_JOURNALRECORD, AddressOf GetMessageProc, App.hInstance, 0)
    If hJournalHook = 0 Then hJournalHook = SetWindowsHookEx(WH_JOURNALRECORD, AddressOf JournalRecordProc, App.hInstance, 0)
   
    If (hAppHook <> 0) And (hJournalHook <> 0) Then
        SetRecordHook = True
    End If
End Function


Friend Function FireRecordEvent(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long)
' This function handles recording of Journal messages
' by raising an event for the application to save.
    RaiseEvent RecordEvent(nCode, wParam, lParam)
End Function


Friend Function SendCancelJournal()
' This routine fires an event to indicate cancel Journal.
    RaiseEvent CancelJournal
End Function


MOUDULE CONTENTS
-------------------------
Public Function JournalRecordProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
' This routine is a handler for Journal Record calls.
  If nCode < 0 Then
     JournalRecordProc = CallNextHookEx(hJournalHook, nCode, wParam, lParam)
     Exit Function
  End If
  ResolvePointer(SHptr).FireRecordEvent nCode, wParam, lParam               ' Destination should save the message
  Call CallNextHookEx(hJournalHook, nCode, wParam, lParam)
End Function


Public Function GetMessageProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
   Dim msg As TMSG
   If nCode < 0 Then
      GetMessageProc = CallNextHookEx(hAppHook, nCode, wParam, lParam)
      Exit Function
   End If
   CopyMemory msg, ByVal lParam, Len(msg)
   Select Case msg.message
       Case WM_CANCELJOURNAL
            If wParam = 1 Then ResolvePointer(SHptr).SendCancelJournal
   End Select
   Call CallNextHookEx(hAppHook, nCode, wParam, ByVal lParam)
End Function


Private Function ResolvePointer(ByVal lpObj&) As cGemSysHook
  Dim oSH As cGemSysHook
  CopyMemory oSH, lpObj, 4&
  Set ResolvePointer = oSH
  CopyMemory oSH, 0&, 4&
End Function
0
gem56
Asked:
gem56
  • 2
  • 2
1 Solution
 
gem56Author Commented:
Hi EDDYKT,
Thanks for yoiur response. I originally based my code on the code you suggested and some other examples however even running the (above) example as is, I'm still not able to trap WM_CANCELJOURNAL message.

Any more suggestions?

/Michael
0
 
gem56Author Commented:
Thanks EDDYKT,
I wasn't able to use the examples from the above links as they were but they gave me ideas to resolve the problem.

/Michael
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now