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

查看:149
本文介绍了我如何知道我是否在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。有没有人知道如何从我的应用程序中获取答案?
  1. If I'm running on a x64 or an x86 processor and
  2. If I'm running under a 64-bit version of Windows under Win32 emulation or native Win32 on a 32-bit OS.

推荐答案



< >解决方案

解决方案

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

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天全站免登陆