Solved

OS conditional statement

Posted on 1998-06-26
8
199 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

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…
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 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.

776 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