how to detect OS architecture?
Regan Heath
regan at netmail.co.nz
Wed Dec 18 05:16:35 PST 2013
On Wed, 18 Dec 2013 04:28:57 -0000, Hugo Florentino <hugo at acdam.cu> wrote:
> On Tue, 17 Dec 2013 13:21:30 -0000, Regan Heath wrote:
>> Is GetNativeSystemInfo your other solution? On the MSDN page for
>> GetNativeSystemInfo it recommends using IsWow64Process to detect if
>> you're running under WOW64, at which point you would then call
>> GetNativeSystemInfo.
>>
>> I am not sure what GetNativeSystemInfo does if called from a 32 bit
>> exe on a 32 bit OS..
>
> It seems to work. After all it makes sense, the native system is
> actually 32 bits.
Cool. The reason I was unsure and the reason I do not agree that it
"makes sense" that it works, is the first paragraph on the MSDN page:
"Retrieves information about the current system to an application
**running under WOW64**. If the function is called from **a 64-bit
application**, it is equivalent to the GetSystemInfo function."
**emphasis mine**
It doesn't actually address the situation of calling it from a 32 bit
application NOT running under WOW64.
GetSystemInfo is callable from both 32 and 64 bit so I assume now, that
given that it works for you, that it is doing what it mentions above for a
64 bit application, and actually just calling GetSystemInfo.
You will probably find that calling GetSystemInfo works just as well as
what you're already doing.
>> I /know/ that the code in std.internal.windows.advapi32 which
>> dynamically loads and calls IsWow64Process will work, because we use
>> it here at work for this very purpose. It's also the simplest most
>> direct way to answer this specific question and it's already present,
>> tested and working in phobos .. so I would be inclined to use it, in
>> preference over GetNativeSystemInfo.
>>
>> R
>
> If after using IsWOW64Process a GetNativeSystemInfo must still be issued
> like you mentioned earlier, I don't see the advantage over calling that
> function directly in the first place.
> Or am I missing something?
Yes, you're missing something :)
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684139(v=vs.85).aspx
IsWow64Process returns (in the output parameter) if the 32 bit application
is running in WOW64. WOW64 *only* exists on a 64 bit OS. So, if true
this tells you you're on a 64 bit OS. You don't need an additional call
to GetNativeSystemInfo at all.
Further, the code is already in phobos so all you actually need to do is
check the isWow64 global boolean defined by
"std.internal.windows.advapi32". So, your code is as simple as:
import std.stdio;
import std.internal.windows.advapi32;
void main(string[] args)
{
writefln(isWow64 ? "yes" : "no");
}
R
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
More information about the Digitalmars-d-learn
mailing list