Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Determing Operating system version during compile time (like _WIN32_WINNT)

Posted on 2003-03-22
9
Medium Priority
?
1,126 Views
Last Modified: 2013-11-13
I have some code which can get compiled in all Operation systems like 95/98/ME/2K/XP but not with NT 4.0. I have defined preprocessor definition and put the code for operation systems other than NT. In NT machine, it works fine but in 98 machine the code does not get executed at all

Here is the psedo-code:

#if (_WIN32_WINNT != 0x0400)
// OS must be other than NT 4.0
   line 1
   line 2
   line 3
#endif

The above code does not get executed in Windows 98

Any solution ?




0
Comment
Question by:pramkumar
7 Comments
 
LVL 4

Accepted Solution

by:
bistrica earned 680 total points
ID: 8187319
There is no WIN32_WINNT on Win98.
Try: Windows 98 & Windows NT 4.0 : _WIN32_WINDOWS=0x0410 & WINVER=0x0400  
0
 
LVL 7

Assisted Solution

by:billious
billious earned 680 total points
ID: 8188761
Since we're talking pseudocode,

shouldn't

#if (_WIN32_WINNT != 0x0400)

be

#if !(_WIN32_WINNT = 0x0400)

??

...Bill
0
 
LVL 8

Assisted Solution

by:adg080898
adg080898 earned 640 total points
ID: 8189255
What? That looks like C, so do this:

------------

BOOL bIs31;          // True when running under Windows 3.1
BOOL bIs9x;          // True when running under Windows 9x
BOOL bIsNT;          // True when running under Windows NT

int nOSMajor, nOSMinor;

int DetectOSVersion(void)
{
     OSVERSIONINFO osvi;

     // Prepare structure for GetVersionEx
     ZeroMemory(&osvi, sizeof(osvi));
     osvi.dwOSVersionInfoSize = sizeof(osvi);

     // Get windows version
     GetVersionEx(&osvi);
     
     // Now I can check the windows version
     switch (osvi.dwPlatformId) {
     case VER_PLATFORM_WIN32s:
          // Windows 3.1 under win32s

          bIs31 = TRUE;

          break;
     case VER_PLATFORM_WIN32_WINDOWS:
          // Win95/98/ME
          // For Windows 95, dwMinorVersion is zero.
          // For Windows 98, dwMinorVersion is greater than zero.

          bIs9x = TRUE;

          break;
     case VER_PLATFORM_WIN32_NT:
          // Win NT/2000/XP

          bIsNT = TRUE;

          break;
     }

     nOSMajor = osvi.dwMajorVersion;
     nOSMinor = osvi.dwMinorVersion;

     return bIs31 || bIs9x || bIsNT;
}

------------

Call this early in your program. Those three globals are initialized to the current version to conditionally execute different code.

You can't check preprocessor macros to see the current OS.
You SET the macros before #include <windows.h> to enable newer structure formats and things. If you use the newer structures, then run the program on older windows, the program will fail.

See:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getversionex.asp

and

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/osversioninfo_str.asp
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 8

Expert Comment

by:adg080898
ID: 8189272
continued from previous post...

After calling above function, do this:

if (!bIsNT || (nOSMajor != 4)) {
    // OS must be other than NT 4.0
    // line 1
    // line 2
    // line 3
}
0
 

Author Comment

by:pramkumar
ID: 8194032
I found a solution... If I use function pointers in all OSs it works fine....

0
 

Expert Comment

by:CleanupPing
ID: 9446896
pramkumar:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 8

Expert Comment

by:adg080898
ID: 9448524
Right, so you could use my OS detection function to know how to initialize your function pointers.

I have used that (function pointer) technique to provide "fallback" functions for InterlockedExchange and InterlockedExchangeAdd, which are not present in Win95.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Make the most of your online learning experience.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question