In an ideal world, everything runs as native bitness (64bit program on 64bit OS, 32bit program on 32bit OS) and life goes on. However, sometimes you need to run that legacy 32bit program on a 64bit OS and need to configure things a little differently as a result. How can you detect this WOW64 case (32bit program on 64bit OS) and act appropriately?
The general idea is to check the following environment variables:
Visually, it looks like:
The logic that I use from a program to detect whether the OS is 32bit or 64bit looks like this:
IF PROCESSOR_ARCHITECTURE == amd64 OR PROCESSOR_ARCHITEW6432 == amd64 THEN // OS is 64bit ELSE // OS is 32bit END IF
Another way to test for the same thing is:
IF PROCESSOR_ARCHITECTURE == x86 AND PROCESSOR_ARCHITEW6432 NOT DEFINED THEN // OS is 32bit ELSE // OS is 64bit END IF
While detection for whether a process is in WOW64 mode is to simply check for the presence of the PROCESSOR_ARCHITEW6432 environment variable.
Now, WHEN would one have to do this? Oh... how about when you are a 32bit application and need to:
Of course, you should realize that WOW64 is just a compatibility shim and NOT an architecture to build/rely upon, so I would keep these sorts of manipulations to a minimum. Sometimes, it is a good idea to not disturb the man behind the curtain...
//David