64 位元應用程式64-bit Applications

您在編譯應用程式時,可以指定其應以原生應用程式在 Windows 64 位元作業系統上或在 WOW64 下 (Windows 64 位元上的 Windows 32 位元) 執行。When you compile an application, you can specify that it should run on a Windows 64-bit operating system either as a native application or under WOW64 (Windows 32-bit on Windows 64-bit). WOW64 是讓 32 位元應用程式可在 64 位元系統上執行的相容性環境。WOW64 is a compatibility environment that enables a 32-bit application to run on a 64-bit system. 所有 64 位元版本的 Windows 作業系統中都包含 WOW64。WOW64 is included in all 64-bit versions of the Windows operating system.

在 Windows 上執行 32 位元及64 位元應用程式。Running 32-bit vs. 64-bit Applications on Windows

所有在 .NET Framework 1.0 或 1.1 上建置的應用程式都會被視為在 64 位元作業系統上的 32 位元應用程式,並一律在 WOW64 和 32 位元 Common Language Runtime (CLR) 下執行。All applications that are built on the .NET Framework 1.0 or 1.1 are treated as 32-bit applications on a 64-bit operating system and are always executed under WOW64 and the 32-bit common language runtime (CLR). .NET Framework 4.NET Framework 4 或更新版本上建置的 32 位元應用程式也會在 64 位元系統的 WOW64 下執行。32-bit applications that are built on the .NET Framework 4.NET Framework 4 or later versions also run under WOW64 on 64-bit systems.

Visual Studio 在 x86 電腦上安裝 CLR 32 位元版本,而在 64 位元 Windows 電腦上同時安裝 32 位元版本和適當的 CLR 64 位元版本。Visual Studio installs the 32-bit version of the CLR on an x86 computer, and both the 32-bit version and the appropriate 64-bit version of the CLR on a 64-bit Windows computer. (由於 Visual Studio 是 32 位元應用程式,所以安裝在 64 位元系統上時,會在 WOW64 下執行。)(Because Visual Studio is a 32-bit application, when it is installed on a 64-bit system, it runs under WOW64.)

注意

X86 模擬和 Itanium 處理器系列之 WOW64 子系統的設計會限制應用程式在一個處理器上執行。Because of the design of x86 emulation and the WOW64 subsystem for the Itanium processor family, applications are restricted to execution on one processor. 這些因素會降低在 Itanium 系統上執行之 32 位元 .NET Framework 應用程式的效能和延展性。These factors reduce the performance and scalability of 32-bit .NET Framework applications that run on Itanium-based systems. 為了增加效能和延展性,我們建議您選用包含 Itanium 系統原生 64 位元支援的 .NET Framework 4.NET Framework 4We recommend that you use the .NET Framework 4.NET Framework 4, which includes native 64-bit support for Itanium-based systems, for increased performance and scalability.

根據預設,當您在 64 位元 Windows 作業系統上執行 64 位元 Managed 應用程式時,可以建立不超過 2 GB 的物件。By default, when you run a 64-bit managed application on a 64-bit Windows operating system, you can create an object of no more than 2 gigabytes (GB). 不過,在 .NET Framework 4.5.NET Framework 4.5 中,您可以提高上限。However, in the .NET Framework 4.5.NET Framework 4.5, you can increase this limit. 如需詳細資訊,請參閱 <gcAllowVeryLargeObjects> 元素For more information, see the <gcAllowVeryLargeObjects> element.

許多組件在 32 位元 CLR 和 64 位元 CLR 上以相同方式執行。Many assemblies run identically on both the 32-bit CLR and the 64-bit CLR. 不過,取決於 CLR,有些程式可能會有不同的行為,若它們包含下列一或多項情形:However, some programs may behave differently, depending on the CLR, if they contain one or more of the following:

  • 包含視平台而變更大小之成員的結構,(例如任何指標類型)。Structures that contain members that change size depending on the platform (for example, any pointer type).

  • 包含常數大小的指標算術。Pointer arithmetic that includes constant sizes.

  • 不正確的平台叫用,或是使用 Int32 而不是 IntPtr 作為控點的 COM 宣告。Incorrect platform invoke or COM declarations that use Int32 for handles instead of IntPtr.

  • IntPtr 轉換到 Int32 的程式碼。Code that casts IntPtr to Int32.

如需如何將 32 位元應用程式移植到 64 位元 CLR 上執行的詳細資訊,請參閱將 32 位元受控碼移轉至 64 位元For more information about how to port a 32-bit application to run on the 64-bit CLR, see Migrating 32-bit Managed Code to 64-bit.

64 位元程式設計的一般資訊General 64-Bit Programming Information

如需 64 位元程式設計的一般資訊,請參閱下列文件:For general information about 64-bit programming, see the following documents:

建立 64 位元應用程式的編譯器支援Compiler Support for Creating 64-Bit Applications

根據預設,當您在 32 位元或 64 位元的電腦上使用 .NET Framework 應用程式建置應用程式時,應用程式會以原生應用程式在 64 位元電腦上執行 (也就是不在 WOW64 下)。By default, when you use the .NET Framework to build an application on either a 32-bit or a 64-bit computer, the application will run on a 64-bit computer as a native application (that is, not under WOW64). 下表列出說明如何使用 Visual Studio 編譯器來建立將會在 WOW64 下以原生執行 (或兩者) 之 64 位元應用程式的文件。The following table lists documents that explain how to use Visual Studio compilers to create 64-bit applications that will run as native, under WOW64, or both.

編譯器Compiler 編譯器選項Compiler option
Visual BasicVisual Basic /platform (Visual Basic)/platform (Visual Basic)
Visual C#Visual C# /platform (C# 編譯器選項)/platform (C# Compiler Options)
Visual C++Visual C++ 您可以使用 /clr:safe 建立各平台適用的 Microsoft 中繼語言 (MSIL) 應用程式。You can create platform-agnostic, Microsoft intermediate language (MSIL) applications by using /clr:safe. 如需詳細資訊,請參閱 /clr (Common Language Runtime 編譯)For more information, see /clr (Common Language Runtime Compilation).

Visual C++ 針對每個 64 位元作業系統包含了個別的編譯器。Visual C++ includes a separate compiler for each 64-bit operating system. 如需如何使用 Visual C++ 建立可在 64 位元 Windows 作業系統上執行之原生應用程式的詳細資訊,請參閱 64 位元程式設計For more information about how to use Visual C++ to create native applications that run on a 64-bit Windows operating system, see 64-bit Programming.

判斷 .exe 檔或 .dll 檔的狀態Determining the Status of an .exe File or .dll File

若要判斷 .exe 檔或 .dll 檔案是否只能在特定平台上或在 WOW64 下執行,請使用不含選項的 CorFlags.exe (CorFlags 轉換工具)To determine whether an .exe file or .dll file is meant to run only on a specific platform or under WOW64, use CorFlags.exe (CorFlags Conversion Tool) with no options. 您也可以使用 CorFlags.exe 來變更 .exe 檔或 .dll 檔的平台狀態。You can also use CorFlags.exe to change the platform status of an .exe file or .dll file. Visual Studio 組件的 CLR 標頭中的執行階段主要版本號碼設為 2,而執行階段次要版本號碼設為 5。The CLR header of a Visual Studio assembly has the major runtime version number set to 2 and the minor runtime version number set to 5. 將次要執行階段版本設定為 0 的應用程式會被視為舊版應用程式,並一律在 WOW64 下執行。Applications that have the minor runtime version set to 0 are treated as legacy applications and are always executed under WOW64.

若要以程式設計方式查詢 .exe 或 .dll 以查看其是否只在特定平台上或在 WOW64 下執行,請使用 Module.GetPEKind 方法。To programmatically query an .exe or .dll to see whether it is meant to run only on a specific platform or under WOW64, use the Module.GetPEKind method.