2011-09-21 98 views
1

我想在C#中創建一個「WH_JOURNALPLAYBACK」鉤子的回調。這是代碼WH_JOURNALPLAYBACK掛鉤在C#

private delegate IntPtr JournalPlaybackProc(int nCode, IntPtr wParam, IntPtr lParam); 

private static IntPtr JournalPlaybackCallback(int nCode, IntPtr wParam, IntPtr lParam) 
{ 
     if (HC_GETNEXT == nCode && curr < EventMsgs.Count) 
     { 
      EVENTMSG hookStruct = (EVENTMSG)Marshal.PtrToStructure(lParam, typeof(EVENTMSG)); 
      EVENTMSG currentMsg = EventMsgs[curr]; 
      hookStruct.message = currentMsg.message; 
      hookStruct.paramL = currentMsg.paramL; 
      hookStruct.paramH = currentMsg.paramH; 
      hookStruct.hwnd = currentMsg.hwnd; 
      hookStruct.time = currentMsg.time; 
     } 
     if (HC_SKIP == nCode) 
     { 
      curr++; 
     } 
     if (curr == EventMsgs.Count) 
     { 
      UnhookWindowsHookEx(_journalPlaybackProcHookID); 
      _journalPlaybackProcHookID = IntPtr.Zero; 
     } 
     return CallNextHookEx(_journalPlaybackProcHookID, nCode, wParam, lParam); 
} 

我得到正確的回調,我想我需要修改的lParam的值與我的數據回放事件。我該怎麼做呢?

+0

我也有同樣的問題。我可以很好地記錄這些值,但播放效果很麻煩。你找到解決方案嗎? – Kelly

回答

0

我假設你需要

Marshal.StructureToPtr(hookStruct,lParam的,真正的);

在某個時刻寫回來。當我運行它只是掛起。