none
有關SetWindowsHookEx的問題 RRS feed

  • 問題

  • 請問各位前輩:

    最近要在Wince5.0上做一個可以攔截鍵盤訊息上的DLL檔,但寫的時候發生一些問題,想跟各位請教,我的程式碼如下:

    Declare Function SetWindowsHookEx Lib "core.dll" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
        Declare Function UnhookWindowsHookEx Lib "core.dll" (ByVal hHook As Long) As Long
        Declare Function CallNextHookEx Lib "core.dll" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        Declare Function LowLevelKeyboardProc Lib "core.dll" Alias "LowLevelKeyboardProcA" (ByVal nCode As Integer, ByVal wParam As Long, ByVal lParam As Long) As Long
        Public Const WH_KEYBOARD_LL = 2
        Private Const HC_ACTION = 0
        Public hHook As Long
        Public Sub UnHookKBD()
            If hHook <> 0 Then
                UnhookWindowsHookEx(hHook)
                hHook = 0
            End If
        End Sub
        Public Function EnableKBDHook()
            If hHook <> 0 Then
                Exit Function
            End If
            hHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, App.Hinstance, 0)
            If hHook <> 0 Then
                EnableKBDHook = hHook
            End If
        End Function
        Public Function LowLevelKeyboardProc(ByVal iCode As Long, _
            ByVal wParam As Long, ByVal lParam As Long) As Long
                   LowLevelKeyboardProc = 0 '訊息要處理
            If iCode < 0 Then
                LowLevelKeyboardProc = CallNextHookEx(hHook, iCode, wParam, lParam)
                Exit Function
            End If
            If wParam =  Then  '偵測 有沒有按到鍵盤值

         我的問題就在於要給wParam的值是要怎麼給,我希望給的是鍵盤輸入的值,不過我不知道在VB上是怎樣設定,麻煩各位教教我
                LowLevelKeyboardProc = 1 '在這個Hook便吃掉這個訊息

            Else
                Call CallNextHookEx(hHook, iCode, wParam, lParam)
            End If
        End Function

     

    另外想問的是用C++寫出來的DLL是用MFC寫的,這個DLL檔可以讓VB.NET或C#使用麼?如果可以該如何用?

    2007年6月27日 上午 09:25

所有回覆