?
Solved

Determing Operating system version during compile time (like _WIN32_WINNT)

Posted on 2003-03-22
9
Medium Priority
?
1,125 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
Six Sigma Control Plans
Introduction to Processes

771 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