如何判断我是否在 x64 上运行? [英] How can I tell if I'm running on x64?

查看:31
本文介绍了如何判断我是否在 x64 上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚收到了一个问题的错误报告,该问题仅在程序在 64 位机器上"运行时才会出现.现在,Delphi 不生成 64 位代码,所以理论上这应该无关紧要,但显然在这种情况下确实如此.我想我有一个解决方法,但它会在 32 位 Windows 上破坏一些东西,所以我需要一些方法来告诉:

I just got a bug report for an issue that only occurs when the program is running "on a 64-bit machine." Now, Delphi doesn't produce 64-bit code, so theoretically that shouldn't matter, but apparently it does in this case. I think I have a workaround, but it will break things on 32-bit Windows, so I need some way to tell:

  1. 如果我在 x64 或 x86 处理器上运行并且
  2. 如果我在 Win32 仿真下的 64 位 Windows 版本或 32 位操作系统上的本机 Win32 下运行.

有谁知道我如何从我的应用中获得这些答案?

Does anyone know how I can get those answers from within my app?

推荐答案

Mason,可以使用 IsWow64Process(WOW64 是 x86 模拟器,它允许基于 Windows 的 32 位应用程序在 64 位 Windows 上无缝运行)

Mason, you can use IsWow64Process (WOW64 is the x86 emulator that allows 32-bit Windows-based applications to run seamlessly on 64-bit Windows)

Uses Windows;

type
  WinIsWow64 = function( Handle: THandle; var Iret: BOOL ): Windows.BOOL; stdcall;


function IAmIn64Bits: Boolean;
var
  HandleTo64BitsProcess: WinIsWow64;
  Iret                 : Windows.BOOL;
begin
  Result := False;
  HandleTo64BitsProcess := GetProcAddress(GetModuleHandle('kernel32.dll'), 'IsWow64Process');
  if Assigned(HandleTo64BitsProcess) then
  begin
    if not HandleTo64BitsProcess(GetCurrentProcess, Iret) then
    Raise Exception.Create('Invalid handle');
    Result := Iret;
  end;
end;

再见.

这篇关于如何判断我是否在 x64 上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆