ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

win32_wrapper.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #define WIN32_LEAN_AND_MEAN
00024 #include <windows.h>
00025 #if defined(__GNUC__) && defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
00026  // required for SHGetSpecialFolderPath in shlobj.h
00027 #define _WIN32_IE 0x400
00028 #endif
00029 #include <shlobj.h>
00030 
00031 #include "common/scummsys.h"
00032 #include "backends/platform/sdl/win32/win32_wrapper.h"
00033 
00034 // VerSetConditionMask, VerifyVersionInfo and SHGetFolderPath didn't appear until Windows 2000,
00035 // so we need to check for them at runtime
00036 ULONGLONG VerSetConditionMaskFunc(ULONGLONG dwlConditionMask, DWORD dwTypeMask, BYTE dwConditionMask) {
00037     typedef ULONGLONG(WINAPI *VerSetConditionMaskFunction)(ULONGLONG conditionMask, DWORD typeMask, BYTE conditionOperator);
00038 
00039     VerSetConditionMaskFunction verSetConditionMask = (VerSetConditionMaskFunction)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "VerSetConditionMask");
00040     if (verSetConditionMask == NULL)
00041         return 0;
00042 
00043     return verSetConditionMask(dwlConditionMask, dwTypeMask, dwConditionMask);
00044 }
00045 
00046 BOOL VerifyVersionInfoFunc(LPOSVERSIONINFOEXA lpVersionInformation, DWORD dwTypeMask, DWORDLONG dwlConditionMask) {
00047     typedef BOOL(WINAPI *VerifyVersionInfoFunction)(LPOSVERSIONINFOEXA versionInformation, DWORD typeMask, DWORDLONG conditionMask);
00048 
00049     VerifyVersionInfoFunction verifyVersionInfo = (VerifyVersionInfoFunction)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "VerifyVersionInfoA");
00050     if (verifyVersionInfo == NULL)
00051         return FALSE;
00052 
00053     return verifyVersionInfo(lpVersionInformation, dwTypeMask, dwlConditionMask);
00054 }
00055 
00056 HRESULT SHGetFolderPathFunc(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPSTR pszPath) {
00057     typedef HRESULT (WINAPI *SHGetFolderPathFunc)(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPSTR pszPath);
00058 
00059     SHGetFolderPathFunc pSHGetFolderPath = (SHGetFolderPathFunc)GetProcAddress(GetModuleHandle(TEXT("shell32.dll")), "SHGetFolderPathA");
00060     if (pSHGetFolderPath)
00061         return pSHGetFolderPath(hwnd, csidl, hToken, dwFlags, pszPath);
00062 
00063     return SHGetSpecialFolderPath(hwnd, pszPath, csidl & !CSIDL_FLAG_MASK, csidl & CSIDL_FLAG_CREATE) ? S_OK : E_NOTIMPL;
00064 }
00065 
00066 namespace Win32 {
00067 
00068 bool confirmWindowsVersion(int majorVersion, int minorVersion) {
00069     OSVERSIONINFOEXA versionInfo;
00070     DWORDLONG conditionMask = 0;
00071 
00072     ZeroMemory(&versionInfo, sizeof(OSVERSIONINFOEXA));
00073     versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
00074     versionInfo.dwMajorVersion = majorVersion;
00075     versionInfo.dwMinorVersion = minorVersion;
00076 
00077     conditionMask = VerSetConditionMaskFunc(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL);
00078     conditionMask = VerSetConditionMaskFunc(conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL);
00079 
00080     return VerifyVersionInfoFunc(&versionInfo, VER_MAJORVERSION | VER_MINORVERSION, conditionMask);
00081 }
00082 
00083 wchar_t *ansiToUnicode(const char *s) {
00084     DWORD size = MultiByteToWideChar(0, 0, s, -1, NULL, 0);
00085 
00086     if (size > 0) {
00087         LPWSTR result = new WCHAR[size];
00088         if (MultiByteToWideChar(0, 0, s, -1, result, size) != 0)
00089             return result;
00090     }
00091 
00092     return NULL;
00093 }
00094 
00095 char *unicodeToAnsi(const wchar_t *s) {
00096     DWORD size = WideCharToMultiByte(0, 0, s, -1, NULL, 0, 0, 0);
00097 
00098     if (size > 0) {
00099         char *result = new char[size];
00100         if (WideCharToMultiByte(0, 0, s, -1, result, size, 0, 0) != 0)
00101             return result;
00102     }
00103 
00104     return NULL;
00105 }
00106 
00107 }


Generated on Sat Feb 16 2019 05:01:11 for ResidualVM by doxygen 1.7.1
curved edge   curved edge