?
Solved

OS conditional statement

Posted on 1998-06-26
8
Medium Priority
?
204 Views
Last Modified: 2010-04-01
I seem to remember something like the psuedocode below to have a program run conditional code depending
on which OS it was on. Does anyone know the correct way to do this?

#if Win95
<do something>
#if WinNT
<do something>

I just need to make a small adjustment if the program in run in NT.
0
Comment
Question by:lucidity
[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
  • 3
  • 3
  • 2
8 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1166710
answer coming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1166711
First of all.  This is not "to have a program run conditional code depending on which OS it was on".  This is "conditional code" that will become part of the program or will be left out of the program depending on what OS the program is being targeted for.   In other words, this is used to create different versions of a program to be used on different OSs.  This is not used to create one program that runs differently on different OSs.  (If that is what you want, let me know.  That is possible, but is done differently,)

if the target OS is windows 95, then the _WIN95 macro will be defined.  You can just use

#ifdef _WIN95
 //// you code.
#endif

if the target OS is windows NT, then the _WINNT macro will be defined.  You can just use

#ifdef _WINNT
 //// you code.
#endif


0
 
LVL 11

Expert Comment

by:alexo
ID: 1166712
lucidity, nietod's code checks what platform the program was COMPILED on, not what platform it executes on.

In order to to the later, you need to do something like:

    OSVERSIONINFO info = { sizeof(OSVERSIONINFO) };
    GetVersionEx(&info);
    if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
    {
        // Do NT stuff
    }
    else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
    {
        // Do 95/98 stuff
    }
    else if (info.dwPlatformId == VER_PLATFORM_WIN32_WIN32s)
    {
        // Do Win32s stuff
    }

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:nietod
ID: 1166713
>> checks what platform the program was COMPILED on

No, it checks what platform the program was compiled FOR, not on.  i.e.   You can make a windows NT targeted program on a windows 95 computer, etc.   (By the way I made that clear (well, tried to) in my answer.)
0
 
LVL 11

Expert Comment

by:alexo
ID: 1166714
>> No, it checks what platform the program was compiled FOR, not on.
I stand corrected.
However, it still won't do any run-time checking.
(The original question said: "I just need to make a small adjustment if the program in run in NT.")
0
 
LVL 2

Author Comment

by:lucidity
ID: 1166715
sorry, I haven't tried it out yet. I will try to get around to it today or Monday.
0
 
LVL 2

Author Comment

by:lucidity
ID: 1166716
Alexco, send back an answer and I will give you an "A".
0
 
LVL 11

Accepted Solution

by:
alexo earned 160 total points
ID: 1166717
Thank you.
For reference: solution in comment from "June 27 1998 - 12:59PM PDT"
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

770 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