【发布时间】:2015-08-14 23:11:13
【问题描述】:
我正在使用 Delphi XE3,在 64 位 Windows 8 机器上构建 32 位和 64 位应用程序。
我正在使用 EnumWindows 来找出给定进程 ID 的进程主窗口的 Windows 句柄。该代码使用回调例程中的 LPARAM 参数来传递指向记录的指针。
我使用的代码在 32 位版本中运行良好。
当我编译和运行 64 位版本时它失败了。出现此问题的原因似乎是在 Wnd 参数中传递 LPARAM 值。 Param 值始终设置为 $FFFF ......换句话说,我根本没有传递 HWND 值......所以它不是通过参数来交换的。
type
PEnumInfo = ^TEnumInfo;
TEnumInfo = record
ProcessID : DWORD;
HWND : THandle;
end;
function EnumWindowsProc(Wnd: HWND; Param : LPARAM): Bool; stdcall;
var
PID : DWORD;
PEI : PEnumInfo;
begin
// in 32-bit Param matches the address of the param that is passed
// in 64-bit Param is set to $FFFF - however Wnd = the expected address
ShowMessage('PEI = '+IntToStr(Param));
PEI := PEnumInfo(Param);
GetWindowThreadProcessID(Wnd, @PID);
// the code fails at this next line in 64-bit build because PEI = $FFFF rather than the actual pointer passed
Result := (PID <> PEI^.ProcessID) or
(not IsWindowVisible(WND)) or
(not IsWindowEnabled(WND));
if not Result then PEI^.HWND := WND; //break on return FALSE
end;
function FindMainWindow(PID: DWORD): DWORD;
var
EI : TEnumInfo;
begin
EI.ProcessID := PID;
EI.HWND := 0;
ShowMessage('PEI = '+IntToStr(LPARAM(@EI)));
EnumWindows(@EnumWindowsProc, LPARAM(@EI));
Result := EI.HWND;
end;
Win64 调用约定是否不同?还是我犯了其他根本性的错误?
感激地接受任何帮助或想法。
【问题讨论】:
-
能否展示一个完整的程序
-
您是要查找 32 位还是 64 位应用程序的主窗口?如果我没记错的话,即使在检索基本进程信息时,您也需要为 32 位和 64 位进程分别编写代码。
-
@Silver 不,所有窗口都被枚举
标签: delphi winapi delphi-xe3 win64