DLL出错,用delphi2006编译出来的DLL会出错,为什么啊 ( 积分: 50 )

  • 主题发起人 主题发起人 my128
  • 开始时间 开始时间
M

my128

Unregistered / Unconfirmed
GUEST, unregistred user!
我很早前写的一个鼠标的HOOK钩子,用delphi7编译出来没有问题,但当我用delphi2006编原来的代码时,在程序应用时出了错误explorer,为什么啊,请高手出招
 
没见代码如何判断!
 
不用看代码吧
 
代码如下:
unit UnitHookDLL;

interface

uses Windows, Messages, Dialogs, SysUtils,UnitHookConst,inifiles;


var
hMappingFile : THandle;
pShMem : PShareMem;
FirstProcess : boolean;
NextHook: HHook;
filename:string;
jbinifile:Tinifile;
jb_int:integer;
function StartHook(sender : HWND;MessageID : WORD) : BOOL; stdcall;
function StopHook: BOOL; stdcall;
procedure GetRbutton; stdcall;

implementation

procedure GetRbutton; stdcall;
begin
pShMem^.IfRbutton:=true;
end;

function HookHandler(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; export;
begin
Result := 0;
If iCode < 0 Then Result := CallNextHookEx(NextHook, iCode, wParam, lParam);

case wparam of
WM_LBUTTONUP:
begin
SendMessage(pShMem^.data1[1],WM_User + 129,wParam,integer(@(pShMem^.data2)) );
end;
WM_LBUTTONDOWN:
begin
SendMessage(pShMem^.data1[1],WM_User + 128,wParam,integer(@(pShMem^.data2)) );
end;
WM_LBUTTONDBLCLK:
begin
SendMessage(pShMem^.data1[1],WM_User + 132,wParam,integer(@(pShMem^.data2)) );
end;
WM_RBUTTONDOWN:
begin
SendMessage(pShMem^.data1[1],WM_User + 130,wParam,integer(@(pShMem^.data2)) );
end;
WM_RBUTTONUP:
begin
SendMessage(pShMem^.data1[1],WM_User + 131,wParam,integer(@(pShMem^.data2)) );
end;
WM_NCLBUTTONDBLCLK:
begin
SendMessage(pShMem^.data1[1],WM_User + 132,wParam,integer(@(pShMem^.data2)) );
end;
WM_NCLBUTTONDOWN:
begin
SendMessage(pShMem^.data1[1],WM_User + 128,wParam,integer(@(pShMem^.data2)) );
end;
WM_NCLBUTTONUP:
begin
SendMessage(pShMem^.data1[1],WM_User + 129,wParam,integer(@(pShMem^.data2)) );
end;
WM_NCRBUTTONDOWN:
begin
SendMessage(pShMem^.data1[1],WM_User + 130,wParam,integer(@(pShMem^.data2)) );
end;
WM_RBUTTONDBLCLK:
begin
end;
WM_MBUTTONDOWN:
begin
end;
WM_MBUTTONUP:
begin
end;
WM_MBUTTONDBLCLK:
begin
end;
WM_NCMouseMove, WM_MOUSEMOVE:
begin
end;
end;
end;

function StartHook(sender : HWND;MessageID : WORD) : BOOL;
function GetModuleHandleFromInstance: THandle;
var
s: array[0..512] of char;
begin
GetModuleFileName(hInstance, s, sizeof(s)-1);
Result := GetModuleHandle(s);
end;
begin
Result := False;
if NextHook <> 0 then Exit;
pShMem^.data1[1]:=sender;
pShMem^.data1[2]:=messageid;
NextHook :=SetWindowsHookEx(WH_mouse, HookHandler, HInstance, 0); //全局
Result := NextHook <> 0;
end;

function StopHook: BOOL;
begin
if NextHook <> 0 then
begin
UnhookWindowshookEx(NextHook);
NextHook := 0;
end;
Result := NextHook = 0;
end;

initialization
hMappingFile := OpenFileMapping(FILE_MAP_WRITE,False,MappingFileName);
if hMappingFile=0 then
begin
hMappingFile := CreateFileMapping($FFFFFFFF,nil,PAGE_READWRITE,0,SizeOf(TShareMem),MappingFileName);
FirstProcess:=true;
end
else FirstProcess:=false;
if hMappingFile=0 then Exception.Create('不能建立共享内存!');

pShMem := MapViewOfFile(hMappingFile,FILE_MAP_WRITE or FILE_MAP_READ,0,0,0);
if pShMem = nil then
begin
CloseHandle(hMappingFile);
Exception.Create('不能映射共享内存!');
end;
if FirstProcess then
begin
pShmem^.IfRbutton := false;
end;
NextHook:=0;
finalization
UnMapViewOfFile(pShMem);
CloseHandle(hMappingFile);
end.
 
unit UnitHookConst;

interface
uses windows;
const
MappingFileName='_MyDllMouse';

type
TShareMem=record
data1:array [1..2] of DWORD;
data2:TMOUSEHOOKSTRUCT;
IfRbutton:boolean;
buffer:array[0..1024]of char;
end;
PShareMem=^TShareMem;

implementation

end.
 
所有代码都贴出来完了
 
高手出来啊,我顶啊
 
神啊,救救我吧[:(!]
 
用D7编译DLL再回D2006里调用就可以了。
 
后退
顶部