It's coded in such a way so you can use an Integer Identifier for a platform to work with switch statements etc and is very simple to use, It comes with an example program/main file to show how to call the CheckOS function, work with switches, conditional if statements and the macros it's self, also a binary version of the example program compiled on win32 and a screen shot (just in-case you're on another platform).
Download http://virtualworld.synthasite.com/reso ... heckOS.zip
Header:
Code: Select all
#include<iostream>
using namespace std;
#if defined _WIN32
#define PLATFORM "Windows32"
#elif defined _WIN64
#define PLATFORM "Windows64"
#elif defined _linux
#define PLATFORM "Linux"
#elif defined _unix
#define PLATFORM "Unix"
#endif
void CheckOS();
int Platform_Int;
void CheckOS()
{
cout<<"http://virtualworld.synthasite.com\n\n";
cout<<"Checking platform...\n\n";
if(PLATFORM == "Windows32")
{
cout<<"\n|Windows 32 bit OS detected|\n";
Platform_Int = 1;
}
else if(PLATFORM == "Windows64")
{
cout<<"\n|Windows 64 bit OS detected|\n";
Platform_Int = 2;
}
else if(PLATFORM == "Linux")
{
cout<<"|Platform Linux detected|\n";
Platform_Int = 3;
}
else if(PLATFORM == "Unix")
{
cout<<"|Platform Unix detected|\n";
Platform_Int = 4;
}
else
{
cout<<"Could not detect OS version with macros from CheckOS.h please check"
"\nthe compiler pre-processor macros and append them to CheckOS.h\n\n";
Platform_Int = 0;
}
}
Example usage:
Code: Select all
/*
__________________________________________________________________
A demonstration on how to use CheckOS.h on it's function and usage
Developed by http://virtualworld.synthasite.com all rights reserved
___________________________________________________________________
*/
//include OS check header
#include "CheckOS.h"
int main()
{
cout<<"Developed by http://virtualworld.synthasite.com\n";
cout<<"This is an example program to show the usage with CheckOS.h\n";
cout<<"Ok now Checking Operating System version:\n\n";
//make one simple call with Check OS (The version will be printed in console
CheckOS();
/*
PLATFORM macros will take and integer identifier so
they can be used with switch statements etc
Hierachy:
OS Integer Identifier
WIN32 Platform_Int = 1
WIN64 Platform_Int = 2
Linux Platform_Int = 3
Unix Platform_Int = 4
OS Macro Not found Platform_Int = 0
*/
cout<<"\nChecking on switch statement:\n";
switch(Platform_Int)
{
case 0: cout<<"OS pre-processor compiler macro not found [fail]\n"; break;
case 1: cout<<"Windows 32 tasks only\n"; break;
case 2: cout<<"Windows 64 tasks only\n"; break;
case 3: cout<<"Linux tasks only\n"; break;
case 4: cout<<"Unix tasks only\n"; break;
}
//you could also easily check it with an if statement if you like, example
cout<<"\nUsing conditional if statements:\n";
if(Platform_Int == 1)
cout<<"Ok the Platform_Int is 1, thus we are in windows 32\n";
else if(Platform_Int == 2)
cout<<"Ok the Platform_Int is 2, thus we are in windows 64\n";
if(Platform_Int == 3)
cout<<"Ok the Platform_Int is 3, thus we are in Linux \n";
if(Platform_Int == 4)
cout<<"Ok the Platform_Int is 1, thus we are in Unix\n";
if(Platform_Int == 0)
cout<<"Ok the Platform_Int is 0, thus can't can't compiler pre-processor macro\n";
//And you can randomly print the OS version if you like, example
cout<<"\nRandom platform macro print out:\n";
cout<<"My platform is "<<PLATFORM<<" thankyou for asking.";
cout<<"\n\n-----------Example program ended-----------\n\n";
system("pause");
return 0;
}
