Solved

OS conditional statement

Posted on 1998-06-26
8
198 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now