View mode: basic / threaded / horizontal-split · Log in · Help
October 10, 2005
Phobos - system.d
This is hardcoded in system.d:

OS os = OS.WindowsNT;

Wouldn't run-time detection be more useful? Considering these definitions:

enum OS
{
Windows95 = 1,
Windows98,
WindowsNT,
Windows2000,

RedHatLinux,
}

Trying to do this myself, my program failed to compile using
OSVERSIONINFO and GetVersionEx. Any Windows library I can link in?

Tommy
October 12, 2005
Re: Phobos - system.d
Yep, I've played with it, and I can't get the D version to work as well
(DMD complains about OSVERSIONINFO and GetVersionEx undefined. The C
version below, however, seems to work well (compiles and runs fine with
DMC 8.45).

Mathias

/*
Detect Windows version at run-time.
Placed into the public domain. ;-)
*/

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

enum OS
/* added Win32s, Windows ME, WindowsXP, Windows2003 (Server Edition),
WindowsVista (Longhorn) */
{
Win32s = 1,
Windows95,
Windows98,
WindowsME,
WindowsNT,
Windows2000,
WindowsXP,
Windows2003,
WindowsVista,

RedHatLinux,
} os;

unsigned int os_major, os_minor;

int main(void)
{
OSVERSIONINFO osversioninfo;

osversioninfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if(GetVersionEx(&osversioninfo))
{
os_major = osversioninfo.dwMajorVersion;
os_minor = osversioninfo.dwMinorVersion;

if(osversioninfo.dwPlatformId == VER_PLATFORM_WIN32s)
os = Win32s;
else if(osversioninfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
{
if(osversioninfo.dwMajorVersion == 4)
{
if(osversioninfo.dwMinorVersion == 0)
os = Windows95;
else if(osversioninfo.dwMinorVersion == 10)
os = Windows98;
else if(osversioninfo.dwMinorVersion == 90)
os = WindowsME;
}
}
else if(osversioninfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
if(osversioninfo.dwMajorVersion == 4)
os = WindowsNT;
if(osversioninfo.dwMajorVersion == 5)
{
if(osversioninfo.dwMinorVersion == 0)
os = Windows2000;
else if(osversioninfo.dwMinorVersion == 1)
os = WindowsXP;
else if(osversioninfo.dwMinorVersion == 2)
os = Windows2003;
}
if(osversioninfo.dwMajorVersion == 6)
os = WindowsVista;
}
}
else /* assume Windows NT if GetVersionEx call fails */
{
os = WindowsNT;
os_major = 4;
os_minor = 0;
}

return EXIT_SUCCESS;
}

In article <diek2e$plb$1@digitaldaemon.com>, Tommy says...

>This is hardcoded in system.d:
>
>OS os = OS.WindowsNT;
>
>Wouldn't run-time detection be more useful? Considering these definitions:
>
>enum OS
>{
>Windows95 = 1,
>Windows98,
>WindowsNT,
>Windows2000,
>
>RedHatLinux,
>}
>
>Trying to do this myself, my program failed to compile using
>OSVERSIONINFO and GetVersionEx. Any Windows library I can link in?
>
>Tommy
>
>
October 12, 2005
Re: Phobos - system.d
Mathias wrote:
> Yep, I've played with it, and I can't get the D version to work as well
> (DMD complains about OSVERSIONINFO and GetVersionEx undefined. The C
> version below, however, seems to work well (compiles and runs fine with
> DMC 8.45).

>>Trying to do this myself, my program failed to compile using
>>OSVERSIONINFO and GetVersionEx. Any Windows library I can link in?
>>


std.c.windows.windows is missing quite a chunk of the Win32 API 
definitions. Whenever something from Windows is undefined, all you need 
do is look in the Windows headers for your C compiler and use that to 
define them in your D module. Or am I missing something?
October 13, 2005
Re: Phobos - system.d
In article <dijtkc$2ddh$1@digitaldaemon.com>, Mike Parker says...

>std.c.windows.windows is missing quite a chunk of the Win32 API 
>definitions. Whenever something from Windows is undefined, all you need 
>do is look in the Windows headers for your C compiler and use that to 
>define them in your D module. Or am I missing something?

Do you mean with copy+paste? Well, that might work. (Haven't tested it
yet, though.) Can we expect any legal problems from Microsoft? ;-)

Mathias
October 13, 2005
Re: Phobos - system.d
In article <dimfvr$2oks$1@digitaldaemon.com>, Mathias says...
>
>In article <dijtkc$2ddh$1@digitaldaemon.com>, Mike Parker says...
>
>>std.c.windows.windows is missing quite a chunk of the Win32 API 
>>definitions. Whenever something from Windows is undefined, all you need 
>>do is look in the Windows headers for your C compiler and use that to 
>>define them in your D module. Or am I missing something?
>
>Do you mean with copy+paste? Well, that might work. (Haven't tested it
>yet, though.) Can we expect any legal problems from Microsoft? ;-)

The MSDN documentation is fair game I think.  And it has callign conventions in
it.  Not as fast as copy+paste, but it's something.


Sean
Top | Discussion index | About this forum | D home