The average lifespan of a typical computer is about 3-5 years. Today, the majority of users are running 32-bit architecture PCs. However, as users begin upgrading to faster computers, they will be moving to the newer 64-bit platforms, requiring some software developers to port their Win32 x32 Visual Studio projects over to the x64 platform. This is particularly important for Windows applications which deal with system processes, hardware, or system architecture. For the developer, converting an application from 32-bit to 64-bit is often a straight forward process in Visual Studio 2008, although there can be subtle issues that may arise.
In this article, we’ll describe how to enumerate the processes running on a Windows-based PC in both a 32-bit and 64-bit platform computer. We’ll list both Win32 and x64 processes and describe the process of converting one to the other in Visual Studio 2008.
There are several methods for enumerating processes running on a PC. We’ll consider the EnumProcesses and EnumProcessModules methods. EnumProcesses allows the Visual Studio 2008 C++ code to walk through and traverse the list of processes running on a PC. When compiled as a 32-bit executable (on a 32-bit computer), EnumProcesses will successfully list all 32-bit (Win32) processes.
The above code is a sample of EnumProcesses implemented from the MSDN tutorial. Notice, the code first enumerates the list of available processes and then walks the process modules to obtain the executable file name. This is the core method of listing processes on the PC.
While the code for enumerating system processes will work perfectly fine when compiled as a 32-bit executable and running on a 32-bit machine, problems begin to arise when running the executable on a 64-bit machine.
Since the size of the process structures differ on the 64-bit architecture, the 32-bit Win32 executable will fail to enumerate 64-bit x64 processes. In fact, if the above code, compiled as a Win32 executable, is ran on a 64-bit machine, it will only return a small subset of the running process - only those processes which are Win32 32-bit. This would almost certainly cause issues in a Win32 program running on a 64-bit machine.
To resolve the problem of enumerating the correct list of processes on the 64-bit machine, the executable will need to be re-compiled as an x64 64-bit executable. Once converted to 64-bit, the EnumProcesses will correctly obtain both 32-bit and 64-bit processes.
The following steps can be made within Visual Studio 2008 to convert the project from Win32 32-bit to x64 64-bit. Note, after converting, there may be some minimal code changes required, such as updating 32-bit specific types.
If you have not yet done so, install the 64-bit architecture extensions, included in the Visual Studio 2008 installation CD. You can add these to an existing Visual Studio install by using the Add/Remove Programs->Update Install option.
Open the 32-bit project in Visual Studio 2008.
In the file menu, click Build and select Configuration Manager.
Pull down the drop-down under “Active solution platform” which currently displays “Win32” and select New.
In the drop-down for “Type or select the new platform”, select “x64”. If x64 does not exist, you will need to install the Visual Studio 2008 64-bit extensions, as shown in step 1.
Click OK. Click Close.
You should now see a drop-down with “x64” selected. In the file menu, select Build and click Rebuild All. Your application will now compile in 64-bit.
Running the application should now display all processes, including 32-bit and 64-bit executables. Note, you will not see processes that you do not have access to, such as csrss.exe and winlogon.exe. To re-compile back in 32-bit, change the drop-down from “x64” back to “Win32” and Rebuild All.
As more PC users begin migrating to x64 64-bit platform computers, software application developers will need to migrate those applications, which deal exclusively with 32-bit items, to run on 64-bit machines. While most 32-bit applications will run correctly on the 64-bit platform, those applications which require system process or 64-bit hardware specific processing may experience issues. Converting a Visual Studio 2008 project from Win32 32-bit to x64 64-bit can be a straight forward process from within the Visual Studio IDE, helping to make the conversion an easier task.
This article was written by Kory Becker, software developer and architect, skilled in a range of technologies, including web application development, machine learning, artificial intelligence, and data science.