L
lyang_1
Unregistered / Unconfirmed
GUEST, unregistred user!
我写了个DLL,用来监控键盘ctrl+B事件。但在调用它里面的函数时遇到不少问题:函数没有响应,或可能是函数返回的值不正确。以下是部分关键代码,请您帮我查错。谢谢。<br>这是生成DLL前的pas里的代码:<br>……<br>function keyboardhookhandler(icode:integer;wparam:wparam;lparam:lparam):<br>lresult;stdcall;export;<br>function enablehotkeyhook:bool;stdcall;export;<br>function disablehotkeyhook:bool;stdcall;export;<br>procedure hotkeyhookexit;far;<br>implementation<br>function keyboardhookhandler(icode:integer;wparam:wparam;lparam:lparam):<br>lresult;stdcall;export;<br>const<br>_keypressmask=$80000000;<br>begin<br>result:=0;<br>if icode<0 then<br>begin<br>result:=callnexthookex(hnexthookproc,icode,wparam,lparam);<br>exit;<br>end;<br>if ((lparam and _keypressmask)=0) and (getkeystate(vk_control)<0) and (wparam=ord('b')) then<br>begin<br>result:=1;<br>winexec('notepad.exe',sw_normal);<br>end ;<br> end;<br>function enablehotkeyhook:bool;stdcall;export;<br>var<br>dll:thandle;<br>pointer;<br>begin<br>result:=false;<br>if hnexthookproc<>0 then exit;<br>dll:=LoadLibrary('C:/My Documents/delphi/delphi.files/hktest.dll');<br>p:=GetProcAddress(dll,'keyboardhookhandler');<br>hnexthookproc:=setwindowshookex(wh_keyboard,p,<br>dll,0);<br>result:=hnexthookproc<>0;<br>end;<br>function disablehotkeyhook:bool;stdcall;export;<br>begin<br>if hnexthookproc<>0 then<br>begin<br>unhookwindowshookex(hnexthookproc);<br>hnexthookproc:=0;<br>messagebeep(0);<br>end;<br>result:=hnexthookproc=0;<br>end;<br>procedure hotkeyhookexit;<br>begin<br>if hnexthookproc<>0 then disablehotkeyhook;<br>exitproc:=procsaveexit;<br>end;<br>end.<br>然后在另外一个新建的PROJECT的BUTTONCLICK事件里调用enablehotkeyhook和<br>disablehotkeyhook,但没有响应,<br>BUTTONCLICK事件只有一条语句:IF enablehotkeyhook THEN SHOWMESSAGE(‘S’),但运行时SHOWMESSAGE没有执行。