CArchSystemWindows.cpp

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2004 Chris Schoeneman
00004  * 
00005  * This package is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * found in the file COPYING that should have accompanied this file.
00008  * 
00009  * This package is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  */
00014 
00015 #define WIN32_LEAN_AND_MEAN
00016 
00017 #include "CArchSystemWindows.h"
00018 #include <windows.h>
00019 
00020 //
00021 // CArchSystemWindows
00022 //
00023 
00024 CArchSystemWindows::CArchSystemWindows()
00025 {
00026     // do nothing
00027 }
00028 
00029 CArchSystemWindows::~CArchSystemWindows()
00030 {
00031     // do nothing
00032 }
00033 
00034 std::string
00035 CArchSystemWindows::getOSName() const
00036 {
00037 #if WINVER >= _WIN32_WINNT_WIN2K
00038     OSVERSIONINFOEX info;
00039 #else
00040     OSVERSIONINFO info;
00041 #endif
00042 
00043     info.dwOSVersionInfoSize = sizeof(info);
00044     if (GetVersionEx((OSVERSIONINFO*) &info)) {
00045         switch (info.dwPlatformId) {
00046         case VER_PLATFORM_WIN32_NT:
00047             #if WINVER >= _WIN32_WINNT_WIN2K
00048             if (info.dwMajorVersion == 6) {
00049                 if(info.dwMinorVersion == 0) {
00050                     if (info.wProductType == VER_NT_WORKSTATION) {
00051                         return "Microsoft Windows Vista";
00052                     } else {
00053                         return "Microsoft Windows Server 2008";
00054                     }
00055                 } else if(info.dwMinorVersion == 1) {
00056                     if (info.wProductType == VER_NT_WORKSTATION) {
00057                         return "Microsoft Windows 7";
00058                     } else {
00059                         return "Microsoft Windows Server 2008 R2";
00060                     }
00061                 }
00062             }
00063             #endif
00064 
00065             if (info.dwMajorVersion == 5 && info.dwMinorVersion == 2) {
00066                 return "Microsoft Windows Server 2003";
00067             }
00068             if (info.dwMajorVersion == 5 && info.dwMinorVersion == 1) {
00069                 return "Microsoft Windows XP";
00070             }
00071             if (info.dwMajorVersion == 5 && info.dwMinorVersion == 0) {
00072                 return "Microsoft Windows Server 2000";
00073             }
00074             if (info.dwMajorVersion <= 4) {
00075                 return "Microsoft Windows NT";
00076             }
00077             char buffer[100];
00078             sprintf(buffer, "Microsoft Windows %d.%d",
00079                             info.dwMajorVersion, info.dwMinorVersion);
00080             return buffer;
00081 
00082         case VER_PLATFORM_WIN32_WINDOWS:
00083             if (info.dwMajorVersion == 4 && info.dwMinorVersion == 0) {
00084                 if (info.szCSDVersion[1] == 'C' ||
00085                     info.szCSDVersion[1] == 'B') {
00086                     return "Microsoft Windows 95 OSR2";
00087                 }
00088                 return "Microsoft Windows 95";
00089             }
00090             if (info.dwMajorVersion == 4 && info.dwMinorVersion == 10) {
00091                 if (info.szCSDVersion[1] == 'A') {
00092                     return "Microsoft Windows 98 SE";
00093                 }
00094                 return "Microsoft Windows 98";
00095             }
00096             if (info.dwMajorVersion == 4 && info.dwMinorVersion == 90) {
00097                 return "Microsoft Windows ME";
00098             }
00099             if (info.dwMajorVersion == 4) {
00100                 return "Microsoft Windows unknown 95 family";
00101             }
00102             break;
00103 
00104         default:
00105             break;
00106         }
00107     }
00108     return "Microsoft Windows <unknown>";
00109 }
00110 
00111 std::string
00112 CArchSystemWindows::getPlatformName() const
00113 {
00114 #ifdef _X86_
00115     if(isWOW64())
00116         return "x86 (WOW64)";
00117     else
00118         return "x86";
00119 #else
00120 #ifdef _AMD64_
00121     return "x64";
00122 #else
00123     return "Unknown";
00124 #endif
00125 #endif
00126 }
00127 
00128 bool
00129 CArchSystemWindows::isWOW64() const
00130 {
00131 #if WINVER >= _WIN32_WINNT_WINXP
00132     typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
00133     LPFN_ISWOW64PROCESS fnIsWow64Process =
00134         (LPFN_ISWOW64PROCESS) GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
00135 
00136     BOOL bIsWow64 = FALSE;
00137     if(NULL != fnIsWow64Process &&
00138         fnIsWow64Process(GetCurrentProcess(), &bIsWow64) &&
00139         bIsWow64)
00140     {
00141         return true;
00142     }
00143 #endif
00144     return false;
00145 }

Generated on Fri Nov 6 00:18:44 2009 for synergy-plus by  doxygen 1.4.7