469,282 Members | 1,977 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

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

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,

--
Newbie Coder
(It's just a name)
Mar 7 '07 #1
6 4863
On Wed, 7 Mar 2007 12:46:42 -0000, Newbie Coder wrote:
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
--
English is not my first, or second, language
so anything strange, or insulting, is due to
the translation.
Please correct me so I may improve my English!
Mar 7 '07 #2
On Wed, 7 Mar 2007 15:41:10 +0100, Anders Eriksson wrote:
On Wed, 7 Mar 2007 12:46:42 -0000, Newbie Coder wrote:
>I need to check to see that the user is using Windows 2000 or later on
program startup. If not, to disable one radiobutton

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
--
English is not my first, or second, language
so anything strange, or insulting, is due to
the translation.
Please correct me so I may improve my English!
Mar 7 '07 #3
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
(It's just a name)
"Anders Eriksson" <an*****@gmail.comwrote in message
news:bj**************@ostling.com...
On Wed, 7 Mar 2007 15:41:10 +0100, Anders Eriksson wrote:
On Wed, 7 Mar 2007 12:46:42 -0000, Newbie Coder wrote:
I need to check to see that the user is using Windows 2000 or later on
program startup. If not, to disable one radiobutton
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
--
English is not my first, or second, language
so anything strange, or insulting, is due to
the translation.
Please correct me so I may improve my English!

Mar 7 '07 #4

"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:Ov*************@TK2MSFTNGP04.phx.gbl...
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?
From C++, you can just #include <windows.hjust like a native program.
Only C# has to mess with DllImport.
>
Awaiting a reponse,

--
Newbie Coder
(It's just a name)
"Anders Eriksson" <an*****@gmail.comwrote in message
news:bj**************@ostling.com...
>On Wed, 7 Mar 2007 15:41:10 +0100, Anders Eriksson wrote:
On Wed, 7 Mar 2007 12:46:42 -0000, Newbie Coder wrote:

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

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
--
English is not my first, or second, language
so anything strange, or insulting, is due to
the translation.
Please correct me so I may improve my English!


Mar 7 '07 #5
"Newbie Coder" <ne*********@spammeplease.comwrote in message
news:Ov*************@TK2MSFTNGP04.phx.gbl...
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.

Mar 7 '07 #6
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,

--
Newbie Coder
(It's just a name)
Mar 8 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Nathan Sokalski | last post: by
12 posts views Thread by Onega | last post: by
4 posts views Thread by bob lambert | last post: by
3 posts views Thread by Jim Richards | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.