Solved

OS conditional statement

Posted on 1998-06-26
8
200 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
  • 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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 40 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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

840 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