- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
delphi检查是否在64位Windows环境中运行?
家64位如何使用Delphi检查是否在64位Windows环境中运行?
标签:64位,Delphi IAmIn64Bits,IsWow64Process,syswow64如何使用Delphi检查是否在64位Windows环境中运行? 2017年5月24日 没意见 64位,代码,代码库,delphi
Win32 API IsWow64Process确定运行的进程(进程处理程序)是否在WOW64上,如果进程是32位且OS是64位,则仅将其设置为TRUE。
在64位Windows上,WOW64(Windows 64位上的Windows 32位)环境中正在运行32位进程。因此,IsWow64Process检查这种情况。
IsWow64Process API在Windows DLL kernel32.dll中定义,可通过LoadLibrary加载。但是,您可以加载一次并为任何后续调用缓存结果。下面通过调用Win32 API IsWow64Process在Delphi中实现IsWow64Process函数。
{$J+}
function IsWow64Process: Boolean;
type
TIsWow64Process = function(hProcess: THandle; var Wow64Process: Boolean): Boolean; stdcall;
var
DLL: THandle;
pIsWow64Process: TIsWow64Process;
const
Called: Boolean = False;
IsWow64: Boolean = False;
begin
if (Not Called) then // only check once
begin
DLL := LoadLibrary('kernel32.dll');
if (DLL <> 0) then
begin
pIsWow64Process := GetProcAddress(DLLHandle, 'IsWow64Process');
if (Assigned(pIsWow64Process)) then
begin
pIsWow64Process(GetCurrentProcess, IsWow64);
end;
Called := True; // avoid unnecessary loadlibrary
FreeLibrary(DLLHandle);
end;
end;
Result := IsWow64;
end;
{$J-}
为了使用Delphi实现这一点,我们使用编译器指令{$ J +},该指令允许可写的类型常量,这类似于C / C ++中的静态变量。带{$ J +}的Called和IsWow64是可写的类型常量,在函数退出时范围不会终止。