Get Windows Version (C++.NET 2003 ONLY)

  • Thread starter Thread starter Newbie Coder
  • Start date Start date
N

Newbie Coder

C++.NET 2003 ONLY

Hi all,

I need to check to see that the user is using Windows 2000 or later on
program startup. If not, to disable one radiobutton

I have searched Google & all I get is C++ or earlier code, but nothing that
compiles in my version of C++.

There is a KBase article, which isn't any good and is here:

http://support.microsoft.com/kb/307393/EN-US/ but that causes an error due
to the MANAGED CODE needs to be set in Configuration Properties | General
(as I found out & reported to Microsoft)

But of course that isn't what I am looking for. I wrote a version in VB.NET
2003 & tried to convert it without success.

Any help would be great as I haven't used C++ for over 7 years now

Thanks in advance,
 
C++.NET 2003 ONLY

Hi all,

I need to check to see that the user is using Windows 2000 or later on
program startup. If not, to disable one radiobutton

I have searched Google & all I get is C++ or earlier code, but nothing that
compiles in my version of C++.

There is a KBase article, which isn't any good and is here:

http://support.microsoft.com/kb/307393/EN-US/ but that causes an error due
to the MANAGED CODE needs to be set in Configuration Properties | General
(as I found out & reported to Microsoft)

But of course that isn't what I am looking for. I wrote a version in VB.NET
2003 & tried to convert it without success.
I'm guessing that you are using VC++ UNMANAGED. the you use the
GetVersionEx() to get windows version.

e.g.

bool IsWindowsXP()
{
OSVERSIONINFO osvi;
bool bIsWindowsXPorLater;

osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx (&osvi);
bIsWindowsXPorLater =
( (osvi.dwMajorVersion > 5) ||
( (osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion >= 1) ));

return bIsWindowsXPorLater;
}

You find more info here:
http://msdn2.microsoft.com/en-us/library/ms724451.aspx

// Anders
 
bool IsWindowsXP()
{
OSVERSIONINFO osvi;
bool bIsWindowsXPorLater;

osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx (&osvi);
bIsWindowsXPorLater =
( (osvi.dwMajorVersion > 5) ||
( (osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion >= 1) ));

return bIsWindowsXPorLater;
}

Oops! I read your mail a bit fast... To check for 2000 and later you change
osvi.dwMinorVersion>=0

You might then want to change the function name ;-)

// Anders
 
Thank you for your replies Anders.

Actually Anders I am using managed code or at least I am using managed code
in my application.

So, surely I have to declare the structure, don't I?

Basically, I am using the DLLIMPORT Attribute so maybe I can declare the
GetVersionEx in that way. Is that correct?

Awaiting a reponse,
 
Newbie Coder said:
Thank you for your replies Anders.

Actually Anders I am using managed code or at least I am using managed
code
in my application.

So, surely I have to declare the structure, don't I?

Basically, I am using the DLLIMPORT Attribute so maybe I can declare the
GetVersionEx in that way. Is that correct?


Awaiting a reponse,
 
Newbie Coder said:
Thank you for your replies Anders.

Actually Anders I am using managed code or at least I am using managed code
in my application.

So, surely I have to declare the structure, don't I?

Basically, I am using the DLLIMPORT Attribute so maybe I can declare the
GetVersionEx in that way. Is that correct?

Awaiting a reponse,

No need to call into native code, the FCL is your friend, take a look at the
System.Diagnostics namespace class OperatingSystem.

Willy.
 
This has now been resolved. Here's the code I used:

using namespace system;

bool Is2000OrLater()
{
OperatingSystem* osInfo = Environment::OSVersion;
PlatformID pID = osInfo->Platform;
switch(pID)
{
case PlatformID::Win32NT:
if (osInfo->Version->Major == 5 && osInfo->Version->Minor >= 0)
return true;
else
return false;
default:
return false;
}
}

Thanks for all your replies,
 
Back
Top