Solved

OS conditional statement

Posted on 1998-06-26
8
197 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

747 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

10 Experts available now in Live!

Get 1:1 Help Now