1 // Copyright 2006, Google Inc.
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are met:
6 // 1. Redistributions of source code must retain the above copyright notice,
7 // this list of conditions and the following disclaimer.
8 // 2. Redistributions in binary form must reproduce the above copyright notice,
9 // this list of conditions and the following disclaimer in the documentation
10 // and/or other materials provided with the distribution.
11 // 3. Neither the name of Google Inc. nor the names of its contributors may be
12 // used to endorse or promote products derived from this software without
13 // specific prior written permission.
15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "gears/base/common/vista_utils.h"
30 // Force GetProcAddress to be defined to the ASCII version in order to
31 // make the call compile.
33 #define GetProcAddress GetProcAddressA
37 bool VistaUtils::IsRunningOnVista() {
38 static DWORD os_major_version
= 0;
39 static DWORD platform_id
= 0;
41 if (0 == os_major_version
) {
42 OSVERSIONINFO os_version
= {0};
43 os_version
.dwOSVersionInfoSize
= sizeof(os_version
);
44 GetVersionEx(&os_version
);
45 os_major_version
= os_version
.dwMajorVersion
;
46 platform_id
= os_version
.dwPlatformId
;
49 return (6 == os_major_version
) && (VER_PLATFORM_WIN32_NT
== platform_id
);
54 bool VistaUtils::IEIsProtectedModeProcess() {
55 if (!IsRunningOnVista()) {
59 typedef HRESULT (WINAPI
*IEIsProtectedModeProcessProc
)(BOOL
*result
);
61 // We use GetModuleHandle here because this call is really only
62 // valid inside IE. IF we are already in IE then ieframe.dll is
63 // already loaded. If we are not running in IE we want to return
64 // a failure code anyway.
65 IEIsProtectedModeProcessProc function
=
66 reinterpret_cast<IEIsProtectedModeProcessProc
>(
68 GetModuleHandle(_T("ieframe.dll")),
69 "IEIsProtectedModeProcess"));
74 BOOL is_protected_mode
= FALSE
;
75 HRESULT hr
= function(&is_protected_mode
);
80 return is_protected_mode
? true : false;
85 bool VistaUtils::GetLocalAppDataLowPath(std::string16
*fullpath
) {
86 if (!IsRunningOnVista()) {
90 HMODULE shell32module
= GetModuleHandle(_T("shell32.dll"));
92 // We depend on shell32.dll having already been loaded
97 // Defined in the platform SDK for Vista
98 const DWORD KF_FLAG_CREATE
= 0x00008000;
99 const GUID FOLDERID_LocalAppDataLow
=
100 {0xA520A1A4, 0x1780, 0x4FF6,
101 {0xBD, 0x18, 0x16, 0x73, 0x43, 0xC5, 0xAF, 0x16}};
103 typedef HRESULT (WINAPI
*SHGetKnownFolderPathProc
)(REFGUID rfid
,
107 SHGetKnownFolderPathProc function
=
108 reinterpret_cast<SHGetKnownFolderPathProc
>(
109 GetProcAddress(shell32module
,
110 "SHGetKnownFolderPath"));
116 HRESULT hr
= function(FOLDERID_LocalAppDataLow
, KF_FLAG_CREATE
, NULL
, &path
);