以下是我写的传递数据的部分代码,有些变量可以不必使用 unit DLL;interfaceuses Windows,Messages;function StartHook:Boolean;stdcall; function EndHook:Boolean;stdcall; function MouseProc(nCode:Integer;wParam:WPARAM;lParam:LPARAM):LongInt;stdcall;const WM_MYMESSAGE=WM_USER+1024;//type // PShareMem=^TShareMem; // TShareMem=record // DATA:TMouseHookStruct; //end;var hMap:THandle; pVoid:Pointer; hMouseHook:HHOOK; DATA:TMouseHookStruct; IsHooked:Boolean; implementation //------------------------------------------------------------------------------function MouseProc(nCode:Integer;wParam:WPARAM;lParam:LPARAM):LongInt;stdcall; begin Result:=0; if nCode < 0 then Result:=CallNextHookEx(hMouseHook,nCode,wParam,lParam); if wParam=WM_LBUTTONDBLCLK then begin //这里写下你自己的代码 end; end; //------------------------------------------------------------------------------ function StartHook:Boolean;stdcall; begin if IsHooked=False then begin hMouseHook:=SetWindowsHookEx(WH_MOUSE,@MouseProc,HInstance,0); if hMouseHook<> 0 then begin IsHooked:=True; Result:=True; end else Result:=False; end; end;
unit DLL;interfaceuses
Windows,Messages;function StartHook:Boolean;stdcall;
function EndHook:Boolean;stdcall;
function MouseProc(nCode:Integer;wParam:WPARAM;lParam:LPARAM):LongInt;stdcall;const
WM_MYMESSAGE=WM_USER+1024;//type
// PShareMem=^TShareMem;
// TShareMem=record
// DATA:TMouseHookStruct;
//end;var
hMap:THandle;
pVoid:Pointer;
hMouseHook:HHOOK;
DATA:TMouseHookStruct;
IsHooked:Boolean;
implementation
//------------------------------------------------------------------------------function MouseProc(nCode:Integer;wParam:WPARAM;lParam:LPARAM):LongInt;stdcall;
begin
Result:=0; if nCode < 0 then
Result:=CallNextHookEx(hMouseHook,nCode,wParam,lParam); if wParam=WM_LBUTTONDBLCLK then
begin
//这里写下你自己的代码
end;
end;
//------------------------------------------------------------------------------
function StartHook:Boolean;stdcall;
begin
if IsHooked=False then
begin
hMouseHook:=SetWindowsHookEx(WH_MOUSE,@MouseProc,HInstance,0);
if hMouseHook<> 0 then
begin
IsHooked:=True;
Result:=True;
end
else
Result:=False;
end;
end;