【问题标题】:Windows 64-bit and 32-bit incompatibilitiesWindows 64 位和 32 位不兼容
【发布时间】:2013-03-12 18:01:45
【问题描述】:

我知道 64 位应用程序需要 64 位 Windows。

哪些 c/c++ 代码仅适用于 64 位或 32 位? 编辑:I have found it here

我能否在运行时确定进程字长:就像我将拥有 32 位应用程序一样,如果操作系统是 32 位或 64 位,它会返回,然后以正确的字长运行子/新进程。

【问题讨论】:

  • 它不叫“bittage”,而是“word size”……你确实为 32 位或 64 位字长编译了 C(或 C++)代码……
  • 通常在安装时决定运行 32 位或 64 位版本的程序,您安装合适的版本,而忽略其他版本。无需在运行时做出决定。
  • 我想知道是否可以做到,我最感兴趣的是是否有一些不兼容的部分
  • @MarkRansom:程序的位数和系统的位数是有区别的。 64位系统可以通过WOW64仿真运行32位程序。例如,32 位程序 Process Explorer 会检测系统是否为 64 位,并在适当时启动自身的 64 位版本。

标签: windows 64-bit 32bit-64bit 32-bit


【解决方案1】:

您可以通过GetNativeSystemInfo 了解您的系统是 32 位还是 64 位。例如,您可以这样做:

typedef void (WINAPI *GetNativeSystemInfo_t)(LPSYSTEM_INFO lpSystemInfo);

BOOL IsSystem64Bit()
{
    HANDLE kernel32 = LoadLibrary("kernel32.dll");
    SYSTEM_INFO si;

    GetNativeSystemInfo_t GetNativeSystemInfoPtr
        = (GetNativeSystemInfo_t)GetProcAddress(kernel32, "GetNativeSystemInfo");

    if (GetNativeSystemInfoPtr == NULL)
        return FALSE;

    GetNativeSystemInfoPtr(&si);
    return (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64);
}

动态解析该函数​​的原因是它在 XP 之前的 Windows 版本中不存在。 (而且在那些版本的 windows 上,我们已经知道系统不是 64 位的)

【讨论】:

    【解决方案2】:

    我不确定 Windows 是否有用,因此显然它的帮助有限,但在 Linux 上,您可以在运行时确定字长。 long int 将是字长。在 64 位 Linux 上 long 是 64 位和 32 位 Linux 上的 32 位。

    所以,这看起来很愚蠢且不一致,但你可以做类似的事情

     char ws[3];
     sprintf(ws, "%d", sizeof(long));
     fprintf(stderr, "%s\n", ws);
    

    然后您可以将ws 与不同的值进行比较,以查看字长。我确信 Windows 有类似的基本类型,可以帮助您判断字长。

    【讨论】:

    猜你喜欢
    • 2023-03-30
    • 2010-10-21
    • 2021-02-08
    • 1970-01-01
    • 1970-01-01
    • 2012-10-26
    • 1970-01-01
    • 1970-01-01
    • 2013-10-21
    相关资源
    最近更新 更多