Thread overview | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
December 16, 2013 how to detect OS architecture? | ||||
---|---|---|---|---|
| ||||
Hi, I am writing a launcher to make a Windows application portable, but since this application supports both x86 and x86_64, I would like to detect the architecture of the OS my launcher is being run on, in order to launch the proper executable. How can I do this? Regards, Hugo |
December 16, 2013 Re: how to detect OS architecture? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hugo Florentino | On Monday, 16 December 2013 at 10:54:15 UTC, Hugo Florentino wrote: > Hi, > > I am writing a launcher to make a Windows application portable, but since this application supports both x86 and x86_64, I would like to detect the architecture of the OS my launcher is being run on, in order to launch the proper executable. > > How can I do this? > > Regards, Hugo version(Windows) { // Windows code goes here } else { // Other OS code goes here } More here: http://dlang.org/version.html |
December 16, 2013 Re: how to detect OS architecture? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jeroen Bollen | > version(Windows) { > // Windows code goes here > } else { > // Other OS code goes here > } > > More here: http://dlang.org/version.html I think he wants determine at runtime what architecture x86 or x64 processor supprots and launch appropriate executable. I think this is what he want http://dlang.org/phobos/core_cpuid.html#.isX86_64 |
December 16, 2013 Re: how to detect OS architecture? | ||||
---|---|---|---|---|
| ||||
Posted in reply to MrSmith | On Mon, 16 Dec 2013 12:40:17 +0100, MrSmith wrote:
>> version(Windows) {
>> // Windows code goes here
>> } else {
>> // Other OS code goes here
>> }
>>
>> More here: http://dlang.org/version.html
>
> I think he wants determine at runtime what architecture x86 or x64
> processor supprots and launch appropriate executable.
>
> I think this is what he want
> http://dlang.org/phobos/core_cpuid.html#.isX86_64
Thanks, that's precisely what I needed :)
|
December 16, 2013 Re: how to detect OS architecture? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hugo Florentino | On Monday, 16 December 2013 at 10:54:15 UTC, Hugo Florentino wrote: > Hi, > > I am writing a launcher to make a Windows application portable, but since this application supports both x86 and x86_64, I would like to detect the architecture of the OS my launcher is being run on, in order to launch the proper executable. > > How can I do this? > > Regards, Hugo http://stackoverflow.com/questions/601089/detect-whether-current-windows-version-is-32-bit-or-64-bit http://support.microsoft.com/kb/556009 To detect environment variables you can use std.process.environment.get |
December 16, 2013 Re: how to detect OS architecture? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hugo Florentino | On Monday, 16 December 2013 at 11:56:07 UTC, Hugo Florentino wrote:
> On Mon, 16 Dec 2013 12:40:17 +0100, MrSmith wrote:
>>> version(Windows) {
>>> // Windows code goes here
>>> } else {
>>> // Other OS code goes here
>>> }
>>>
>>> More here: http://dlang.org/version.html
>>
>> I think he wants determine at runtime what architecture x86 or x64
>> processor supprots and launch appropriate executable.
>>
>> I think this is what he want
>> http://dlang.org/phobos/core_cpuid.html#.isX86_64
>
> Thanks, that's precisely what I needed :)
Are you sure?
This will tell you about the processor, but not necessarily about what the OS supports. I don't know, but you may find that when using windows 32bit on an x64 machine, cpuid will tell you the cpu is 64bit, but the OS won't let you run any 64bit code.
|
December 16, 2013 Re: how to detect OS architecture? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hugo Florentino | On Monday, 16 December 2013 at 10:54:15 UTC, Hugo Florentino wrote:
> Hi,
>
> I am writing a launcher to make a Windows application portable, but since this application supports both x86 and x86_64, I would like to detect the architecture of the OS my launcher is being run on, in order to launch the proper executable.
>
> How can I do this?
>
> Regards, Hugo
version (Windows)
{
version (X86_64)
{
// 64bit code.
}
version (X86)
{
32bit code.
}
}
|
December 16, 2013 Re: how to detect OS architecture? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | On 12/16/2013 9:26 PM, Gary Willoughby wrote:
> On Monday, 16 December 2013 at 10:54:15 UTC, Hugo Florentino wrote:
>> Hi,
>>
>> I am writing a launcher to make a Windows application portable, but
>> since this application supports both x86 and x86_64, I would like to
>> detect the architecture of the OS my launcher is being run on, in
>> order to launch the proper executable.
>>
>> How can I do this?
>>
>> Regards, Hugo
>
> version (Windows)
> {
> version (X86_64)
> {
> // 64bit code.
> }
>
> version (X86)
> {
> 32bit code.
> }
> }
That will tell him the version of Windows the executable was compiled on, but won't help him much when running a 32-bit executable on a 64-bit OS. He wants to detect the run-time architecture.
|
December 16, 2013 Re: how to detect OS architecture? | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On Mon, 16 Dec 2013 12:59:52 +0100, John Colvin wrote:
> On Monday, 16 December 2013 at 11:56:07 UTC, Hugo Florentino wrote:
>> On Mon, 16 Dec 2013 12:40:17 +0100, MrSmith wrote:
>>> I think this is what he want
>>> http://dlang.org/phobos/core_cpuid.html#.isX86_64
>>
>> Thanks, that's precisely what I needed :)
>
> Are you sure?
>
> This will tell you about the processor, but not necessarily about
> what the OS supports. I don't know, but you may find that when using
> windows 32bit on an x64 machine, cpuid will tell you the cpu is 64bit,
> but the OS won't let you run any 64bit code.
You are right. I realized that this function was not quite what I needed when running this code on a 32 bit system:
import std.stdio, core.cpuid;
int main() {
immutable auto appname = "myapp";
auto appversion = !isX86_64() ? appname ~ "32" : appname ~ "64") ~ ".exe";
scope(failure) return -1;
writeln(appversion);
return 0;
}
I was expecting "myapp32.exe" but got "myapp64.exe". Apparently what isX86_64() detects is the capability of the processor, not the arquitecture of the OS.
So currently D has no specific function for detecting the OS architecture at runtime? I had not expected this.
I will try using the other options though. Thanks
|
December 16, 2013 Re: how to detect OS architecture? | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | Am Mon, 16 Dec 2013 12:59:52 +0100 schrieb "John Colvin" <john.loughran.colvin@gmail.com>: > On Monday, 16 December 2013 at 11:56:07 UTC, Hugo Florentino wrote: > > On Mon, 16 Dec 2013 12:40:17 +0100, MrSmith wrote: > >>> version(Windows) { > >>> // Windows code goes here > >>> } else { > >>> // Other OS code goes here > >>> } > >>> > >>> More here: http://dlang.org/version.html > >> > >> I think he wants determine at runtime what architecture x86 or > >> x64 > >> processor supprots and launch appropriate executable. > >> > >> I think this is what he want http://dlang.org/phobos/core_cpuid.html#.isX86_64 > > > > Thanks, that's precisely what I needed :) > > Are you sure? > > This will tell you about the processor, but not necessarily about what the OS supports. I don't know, but you may find that when using windows 32bit on an x64 machine, cpuid will tell you the cpu is 64bit, but the OS won't let you run any 64bit code. ...and your launcher would in turn fail to work on my Vista Home Premium 32-bit, which came pre-installed on a 64-bit system. -- Marco |
Copyright © 1999-2021 by the D Language Foundation