Recently, I want to compatible my program with a 64-bit system. I thought it was a big project. However, after reading the relevant information, I found this is not difficult. Generally, 32-bit programs can run on 64-bit systems. Of course, this is mainly because the 64-bit system has considered this transition. First, you must know that the 64 system has prepared an environment for 32-bit applications to run the 32-bit program, which is WOW64. WOW64 is short for Windows-32-on-Windows-64. It provides 32-bit Simulation for existing 32-bit applications, enabling most 32-bit applications to run on Windows 64-bit without modification. It is similar to the old WOW32 subsystem and runs 16-bit code in Windows 32-bit version.
Next we will introduce some things to be used in programming.
1. Of course, you must also use the following method to determine whether the system is a 32-bit system or a 64-bit system? If you want to use a small change, you must know whether it is 32 or 64. If IsWow64 returns TRUE, it is a 64-bit system; otherwise, it is a 32-bit system. Code: typedef BOOL (WINAPI * LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); Define fnIsWow64Process; BOOL IsWow64 () {BOOL bIsWow64 = FALSE; fnIsWow64Process = (callback) getProcAddress (GetModuleHandle (TEXT ("kernel32"), "IsWow64Process"); if (NULL! = FnIsWow64Process) {if (! FnIsWow64Process (GetCurrentProcess (), & bIsWow64) {// handle error AfxMessageBox ("IsWow64 error! ") ;}} Return bIsWow64;} 2. About the registry. If you go to the vista64 registry, you will find that the Registry has changed a lot in terms of program installation and uninstallation. But the good news is. Run Wow64 in your program. So you don't need to worry about the changes. This WOW64 will help you switch. Of course, this is only limited to some standard registry location changes, but you need to test it on your own. This change is mainly due to the fact that the 64-bit program installed in vista64 is significantly different from the 32-bit program in the installation location, because there is an additional program file (x ). For example, in the list of uninstalled programs: xp is located at the following position: HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Uninstallvista64: HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \ Microsoft \ Windows \ CurrentVersion \ Uninstall \ However, If you access HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Uninstall in vista, there is no problem.
In xp, the specific program is located in HKEY_LOCAL_MACHINE \ SOFTWAREvista, which is located in HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node. If you still access the following location under vista64, HKEY_LOCAL_MACHINE \ SOFTWARE: the list of HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node in vista. In this case, WOW is actually converted. Therefore, you don't have to worry about problems. Of course, some non-standard locations may change. But don't worry. These are rarely used.
Introduction to WOW64:
The hardware itself has a 32-bit compatibility mode that can handle the actual execution of IA-32 commands, while the WOW layer handles transactions such as switching the processor between 32-bit and 64-bit modes and simulating 32-bit systems. For example, 32-bit and 64-bit programs have different registry configuration units. There is also a different system directory for 32-bit binary files. The 64-bit binary file still uses the System32 directory. Therefore, when a 32-bit application is installed in the system, the WOW layer ensures that the 32-bit binary file is placed in a new directory SysWOW64. This is achieved through the following method: intercept API calls, such as GetSystemDirectory, based on whether the application is running under WOW and return the appropriate directory. The same issue may exist in the registry. Because both 32-bit and 64-bit COM servers can be installed on the system and are located under the same Class Identifier (CLSID, therefore, the WOW layer needs to redirect registry calls to the appropriate 32-bit or 64-bit configuration units. The WOW layer also handles image changes between certain regions in the Registry to make it easier to support interaction between 32-bit and 64-bit code. WOW64 is very important because it allows you to use most of the existing 32-bit code without worrying about performance and scalability issues. It is the best combination of the two methods. You can migrate your service to 64-bit while retaining the Microsoft Management Console (MMC) Configuration Management Unit as 32-bit. Windows 64-bit versions include the 32-bit and 64-bit versions of MMC. When the Retention management tool is set to 32-bit, communication between processes may encounter some problems, but as long as the interface design is correct, such as Remote Procedure Call (RPC) the protocol should be able to run between 32-bit and 64-bit processes. Another thing to note about WOW64 is that it is not designed for applications requiring high performance. At least, the WOW64 subsystem needs to extend the 32-bit parameter to 64-bit, And the 64-bit return value must be truncated to 32-bit. In the worst case, the WOW64 subsystem will need to call the kernel, not only the conversion to the kernel, there is also a conversion from the 32-bit compatibility mode of the processor to the 64-Bit mode of its local machine. When running in WOW64, the application cannot be properly adjusted. For applications that you want to retain as 32-bit, test them in WOW64. If the performance does not meet your expectations, you need to consider migrating the application to 64-bit. WOW64 is implemented in user mode and serves as the layer between ntdll. dll and kernel. WOW64 and some of its supported DLL files are only 64-bit DLL files that can be loaded to 32-bit processes. In all other cases, the process remains pure. 32-bit processes cannot load 64-bit DLL, and vice versa. It seems that you are clear about the above. Generally, the program does not need to be transplanted. However, if drivers are involved, such as driver installation, these need to be transplanted. Because the driver is installed in the kernel for running, the 32-bit driver does not work.