GetEnvironmentVariable() x64 x86 issue.

Windows specific forum
Lucifer
User
User
Posts: 26
Joined: Wed Apr 30, 2003 6:11 pm
Location: UK

GetEnvironmentVariable() x64 x86 issue.

Post 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
User avatar
TI-994A
Addict
Addict
Posts: 2700
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: GetEnvironmentVariable() x64 x86 issue.

Post 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. :)
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: GetEnvironmentVariable() x64 x86 issue.

Post by Fred »

Yes, it does look OK to me as well, as default program files are x86 for a 32-bit program.
Lucifer
User
User
Posts: 26
Joined: Wed Apr 30, 2003 6:11 pm
Location: UK

Re: GetEnvironmentVariable() x64 x86 issue.

Post 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.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: GetEnvironmentVariable() x64 x86 issue.

Post by ts-soft »

The redirection of some environmentvars, paths and registryentries is not so easy to understand and is not always logical :mrgreen:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
PureGuy
Enthusiast
Enthusiast
Posts: 102
Joined: Mon Aug 30, 2010 11:51 am

Re: GetEnvironmentVariable() x64 x86 issue.

Post by PureGuy »

For programs running under WoW emulation, there are 2 different variables available.

Code: Select all

Debug GetEnvironmentVariable("CommonProgramW6432")
Debug GetEnvironmentVariable("ProgramW6432")
Post Reply