.. OK . es geht !
Hab auf Desktop XP 32bit
Hab auf Notebook Win7 64 Bit
Auf beiden Lazarus installiert..
am XP hab ich stratHook und StopHook mit der Zahl 32 erweitert und das Projet als versatile32 gespeichert und compiliert
am Win7 hab ich stratHook und StopHook mit der Zahl 64 erweitert und das Projet als versatile64 gespeichert und compiliert
In meiner 32Bit Delphi 7 Anwendung (für die der Tastaturhook ist..) hab ich
Delphi-Quellcode:
procedure DllMessage(var Msg: TMessage); message WM_USER + 8765;
end;
function StartHook32(AppHandle: HWND): Boolean; stdcall; external 'versatile32.dll';
function StopHook32: Boolean; stdcall; external 'versatile32.dll';
function StartHook64(AppHandle: HWND): Boolean; stdcall; external 'versatile64.dll';
function StopHook64: Boolean; stdcall; external 'versatile64.dll';
Um zu entscheiden, welche
DLL ich verwende:
Delphi-Quellcode:
function TVersatile_main_handle.IsWow64: Boolean;
type
TIsWow64Process =
function(
// Type of IsWow64Process API fn
Handle: Windows.THandle;
var Res: Windows.BOOL
): Windows.BOOL;
stdcall;
var
IsWow64Result: Windows.BOOL;
// Result from IsWow64Process
IsWow64Process: TIsWow64Process;
// IsWow64Process fn reference
begin
// Try to load required function from kernel32
IsWow64Process := Windows.GetProcAddress(
Windows.GetModuleHandle('
kernel32.dll'), '
IsWow64Process'
);
if Assigned(IsWow64Process)
then
begin
// Function is implemented: call it
if not IsWow64Process(
Windows.GetCurrentProcess, IsWow64Result
)
then
raise SysUtils.Exception.Create('
IsWow64: bad process handle');
// Return result of function
Result := IsWow64Result;
end
else
// Function not implemented: can't be running on Wow64
Result := False;
if result = true
then gl_st_osbit := '
64 Bit';
if result = false
then gl_st_osbit := '
32 Bit';
end;
Start Hook:
Delphi-Quellcode:
if gl_st_osbit = '
64 Bit'
then StartHook32(
handle);
if gl_st_osbit = '
32 Bit'
then StartHook64(
handle);
Stop Hook
Delphi-Quellcode:
if gl_st_osbit = '64 Bit' then StopHook32;
if gl_st_osbit = '32 Bit' then StopHook64;
Der FreePascal Code für die
DLL´s:
Delphi-Quellcode:
library Versatile32;
{$mode objfpc}{$H+}
{$IFDEF WINDOWS}{$R Versatile32.rc}{$ENDIF}
uses
Classes,
Windows,
ActiveX,
ShlObj,
Messages,
SysUtils;
var
HookHandle: Cardinal = 0;
AppHandle: HWND;
function KeyboardHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT;
stdcall;
begin
Result := CallNextHookEx(HookHandle,
nCode,
wParam,
lParam);
if nCode = HC_NOREMOVE
then
Exit;
// if nCode = HC_ACTION then
if wParam = VK_F4
then
begin
PostMessage(FindWindow(
nil,'
Versatile'),
WM_USER + 8765,
300,
0);
end
else
begin
PostMessage(FindWindow(
nil,'
Versatile'),
WM_USER + 8765,
wParam,
lParam);
end;
end;
function StartHook32(ApplicationHandle: HWND): Boolean;
stdcall;
begin
Result := False;
if HookHandle = 0
then
begin
HookHandle := SetWindowsHookEx(WH_KEYBOARD,
@KeyboardHookProc,
HInstance,
0);
AppHandle := ApplicationHandle;
Result := TRUE;
end;
end;
function StopHook32: Boolean;
stdcall;
begin
Result := UnhookWindowsHookEx(HookHandle);
HookHandle := 0;
end;
exports
StartHook32,
StopHook32;
end.
Erich Wanker - for life:=1971 to lebensende do begin ..