by M.S. » 2007年2月03日(土) 18:28
自分でやってみて、このようになりました。
間違いがたくさんあると思います。
一応全部載せておきます。
[ここをクリックすると内容が表示されます] [ここをクリックすると非表示にします]コード: 全て選択
#include "HOOK.idx"
'-------------------------------------------------------------------
' メモ - このファイルには、DLLの構成要素を記述します。
' (例:関数定義、グローバル変数、定数定義など)
'
' エクスポートが必要な関数には、"Export" 修飾子を指定します。
' (例:Function Export FuncName() As Long)
'-------------------------------------------------------------------
Function Export DllMain(hinstDLL As HINSTANCE, fdwReason As DWord, lpvReserved As VoidPtr) As Long
'DLLエントリポイント
Select Case fdwReason
Case DLL_PROCESS_ATTACH
'DLLがプロセス空間にロードされた時に実行されます。
_System_StartupProgram()
DllMain=1
End Select
End Function
declare function SetWindowsHookEx lib "user32" alias "SetWindowsHookExA" (idHook As DWord,lpfn As HINSTANCE,hMod As HINSTANCE,dwThreadId As DWord) as long
declare function UnhookWindowsHookEx lib "user32" (ByVal hhk As Long) as long
const WH_KEYBOAD=2
dim hMyHook=0 as HINSTANCE
dim hInst as HINSTANCE
function Export SetHook()
hMyHook=SetWindowsHookEx(WH_KEYBOAD,AddressOf(MyHookProc),hInst,0)
if hMyHook=NULL then
MessageBox(0,"フックに失敗","dll",MB_OK)
Else
MessageBox(0,"フックに成功","dll",MB_OK)
End If
return 0
End Function
function Export ResetHook()
if UnhookWindowsHookEx(hMyHook)=0 then
MessageBox(0,"フック解除に成功","dll",MB_OK)
End If
return 0
End Function
function Export MyHookProc(nCode As Integer,wp As WPARAM,lp As LPARAM) As DWord
dim str[256] as char
if nCode<0 then
return CallNextHookEc(hMyHook,nCode,wp,lp)
End If
if wp>=0x30 And wp<=0x39 then
wsprintf(str,"hMyHook = %d",hMyHook)
MessageBox(0,str,"MyHookProc",MB_OK)
return CallNextHookEx(hMyHook,nCode,wp,lp)
End If
wsprintf(str,Ex"キー入力はインターセプトされました。\r\nフックハンドル = %d",hMyHook)
MessageBox(0,str,"インターセプト",MB_OK)
return TRUE
End Function
HOOK.abp(55) - "0x30" 無効な識別子です
HOOK.abp(55) - "0x39" 無効な識別子です
というエラーが出ます。
これはどうすれば良いのでしょうか?
自分でやってみて、このようになりました。
間違いがたくさんあると思います。
一応全部載せておきます。
[hide][code]#include "HOOK.idx"
'-------------------------------------------------------------------
' メモ - このファイルには、DLLの構成要素を記述します。
' (例:関数定義、グローバル変数、定数定義など)
'
' エクスポートが必要な関数には、"Export" 修飾子を指定します。
' (例:Function Export FuncName() As Long)
'-------------------------------------------------------------------
Function Export DllMain(hinstDLL As HINSTANCE, fdwReason As DWord, lpvReserved As VoidPtr) As Long
'DLLエントリポイント
Select Case fdwReason
Case DLL_PROCESS_ATTACH
'DLLがプロセス空間にロードされた時に実行されます。
_System_StartupProgram()
DllMain=1
End Select
End Function
declare function SetWindowsHookEx lib "user32" alias "SetWindowsHookExA" (idHook As DWord,lpfn As HINSTANCE,hMod As HINSTANCE,dwThreadId As DWord) as long
declare function UnhookWindowsHookEx lib "user32" (ByVal hhk As Long) as long
const WH_KEYBOAD=2
dim hMyHook=0 as HINSTANCE
dim hInst as HINSTANCE
function Export SetHook()
hMyHook=SetWindowsHookEx(WH_KEYBOAD,AddressOf(MyHookProc),hInst,0)
if hMyHook=NULL then
MessageBox(0,"フックに失敗","dll",MB_OK)
Else
MessageBox(0,"フックに成功","dll",MB_OK)
End If
return 0
End Function
function Export ResetHook()
if UnhookWindowsHookEx(hMyHook)=0 then
MessageBox(0,"フック解除に成功","dll",MB_OK)
End If
return 0
End Function
function Export MyHookProc(nCode As Integer,wp As WPARAM,lp As LPARAM) As DWord
dim str[256] as char
if nCode<0 then
return CallNextHookEc(hMyHook,nCode,wp,lp)
End If
if wp>=0x30 And wp<=0x39 then
wsprintf(str,"hMyHook = %d",hMyHook)
MessageBox(0,str,"MyHookProc",MB_OK)
return CallNextHookEx(hMyHook,nCode,wp,lp)
End If
wsprintf(str,Ex"キー入力はインターセプトされました。\r\nフックハンドル = %d",hMyHook)
MessageBox(0,str,"インターセプト",MB_OK)
return TRUE
End Function[/code][/hide]
HOOK.abp(55) - "0x30" 無効な識別子です
HOOK.abp(55) - "0x39" 無効な識別子です
というエラーが出ます。
これはどうすれば良いのでしょうか?