Page 1 of 1
GetEnvironmentVariable() x64 x86 issue.
Posted: Fri Apr 25, 2014 10:32 am
by Lucifer
I seem to have found a problem with GetEnvironmentVariable(). I'm using 5.22 LTS x64 IDE on Windows 8.1(Update 1) x64 (8.0 to 8.1 upgrade) and have the problem on the same set-up on my laptop.
Sample code –
Code: Select all
Debug GetEnvironmentVariable("CommonProgramFiles")
Debug GetEnvironmentVariable("CommonProgramFiles(x86)")
If in the compiler options you set the compiler to the default 5.22 LTS x64 compiler then the result is as expected –
C:\Program Files\Common Files
C:\Program Files (x86)\Common Files
I have the x86 compiler version also installed and selecting the 5.22 LTS x86 compiler and running the same code I now get –
C:\Program Files (x86)\Common Files
C:\Program Files (x86)\Common Files
Re: GetEnvironmentVariable() x64 x86 issue.
Posted: Fri Apr 25, 2014 11:15 am
by TI-994A
Lucifer wrote:Code: Select all
Debug GetEnvironmentVariable("CommonProgramFiles")
Debug GetEnvironmentVariable("CommonProgramFiles(x86)")
5.22 LTS x64 compiler
C:\Program Files\Common Files
C:\Program Files (x86)\Common Files
5.22 LTS x86 compiler
C:\Program Files (x86)\Common Files
C:\Program Files (x86)\Common Files
Hi Lucifer. I believe that the results are as it should be, as 32bit apps have no access to the 64bit environment. The WoW64 subsystem in 64bit versions of Windows performs a redirection for backward compatibility.

Re: GetEnvironmentVariable() x64 x86 issue.
Posted: Fri Apr 25, 2014 11:22 am
by Fred
Yes, it does look OK to me as well, as default program files are x86 for a 32-bit program.
Re: GetEnvironmentVariable() x64 x86 issue.
Posted: Fri Apr 25, 2014 12:15 pm
by Lucifer
Interesting.
I understand the limitations imposed by the OS in this situation. I did read the manual of which it said “Returns the content of the specified environment variable from the programs environment block”. It’s easy to see how it could be misunderstood and I apologise for the inconvenience.
Re: GetEnvironmentVariable() x64 x86 issue.
Posted: Fri Apr 25, 2014 12:42 pm
by ts-soft
The redirection of some environmentvars, paths and registryentries is not so easy to understand and is not always logical

Re: GetEnvironmentVariable() x64 x86 issue.
Posted: Fri Apr 25, 2014 5:30 pm
by PureGuy
For programs running under WoW emulation, there are 2 different variables available.
Code: Select all
Debug GetEnvironmentVariable("CommonProgramW6432")
Debug GetEnvironmentVariable("ProgramW6432")