2014-02-17 107 views
0

我已經在模塊中使用這個幫助類:http://tinyurl.com/pb3vxw6和我有以下問題:SetWindowsHookEx總是返回零值。正如我所提到的,這個API函數沒有記錄。 Win CE 6.0設備是否仍支持此API函數?我應該使用另一個API函數嗎?如何以另一種方式實現鍵盤掛鉤?處理SetWindowsHookEx零返回值

public void Start() 
{ 
    if (hHook != 0) 
    { 
     // Unhook the previouse one 
     this.Stop(); 
    } 

    hookDeleg = new HookProc(HookProcedure); 
    // in hHook returned zero value 
    hHook = SetWindowsHookEx(WH_KEYBOARD_LL, hookDeleg, GetModuleHandle(null), 0); 

    if (hHook == 0) 
    { // Exception throwed 
     throw new SystemException("Failed acquiring of the hook."); 
     // May be better? 
     // Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error()); 

    } 
} 
+1

未記錄==預計不工作。如果[圖像構建正確],鼠標掛鉤可以工作(http://blogs.msdn.com/b/raffael/archive/2008/05/12/setwindowshookex-on-windows-mobile.aspx)。 –

+1

[QASetWindowsJournalHook](http://www.codeproject.com/Articles/122754/Using-Input-Hooks-in-Windows-Mobile)能更好地工作嗎? – PaulH

+0

您的代碼可以在Windows CE 6.0/5.0設備上使用? – hellboy

回答

1

這個程序或DLL?你需要DLL來獲取鍵盤鉤子(並鉤住你的DLL鍵盤)。我應該通過hInstance而不是GetModuleHandle(null)。所以當你掛鉤鍵盤窗口實際上調用該DLL。