Is there a way to identfy Windows version?

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Nov 21 01:11:39 PST 2016


On Monday, November 21, 2016 08:57:11 Bauss via Digitalmars-d-learn wrote:
> Is there a way to identify the Windows version? Such as if it's
> XP, Vista, 7, 8 or 10? Either some way to tweak with version
> flags or something in the standard library.

Phobos doesn't have anything like that, but you can use the C functions from
the Windows API to do it. A quick search turned up GetVersion and
GetVersionExA/W:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/ms724451(v=vs.85).aspx

Bindings for those seems to be in core.syse.windows.winbase. So, if you
import it, you can call them. There are also these functions

https://msdn.microsoft.com/en-us/library/windows/desktop/dn424972(v=vs.85).aspx

but druntime doesn't seem to have bindings for them at the moment. So, if
you want to use them, you'll either have to declare the bindings yourself or
find a project that already did. Looking at code.dlang.org, there's this
one:

http://code.dlang.org/packages/windows-headers

Someone may have a better suggestion though if you're looking for a fuller
set of Windows bindings (the ones in druntime have improved over time, but
they're still missing a lot). Personally, I don't do much with Windows and
D. So, I'm not well-versed with the best way to get the bindings for the
Windows API.

Ultimately though, the answer to your question is that you're going to need
to call Microsoft's C functions using D bindings to those functions.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list