1 // Copyright 2007, 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.
26 // TODO(andreip): remove platform-specific #ifdef guards when OS-specific
27 // sources (e.g. WIN32_CPPSRCS) are implemented
29 #ifndef GEARS_BASE_COMMON_WINCE_COMPATIBILITY_H__
30 #define GEARS_BASE_COMMON_WINCE_COMPATIBILITY_H__
35 #include <connmgr_status.h>
39 #include "gears/localserver/common/critical_section.h"
41 // The Win32 code uses ::PathFindXXXW. These are defined in shlwapi.h, but the
42 // WinCE SDK does not provide shlwapi.lib. Instead it provides
43 // ATL::PathFindXXX, which are defined in atlosapice.h (included from
44 // atlbase.h). However, ATL::PathFindXXX is not provided by the Win32 SDK.
45 // Therefore we use ATL::PathFindXXX for WinCE only and use a 'using'
46 // declaration to keep the code identical for the two platforms.
48 // Note that atlosapice.h provides a define from PathFindExtension to
49 // PathFindExtensionW, but not for PathFindFileNameW. shlwapi.h provides defines
50 // for both functions, but inclduing this file introduces ambiguity between the
51 // ATL::PathFindXXXW and ::PathFindXXXW functions.
53 #define PathFindFileNameW PathFindFileName
55 using ATL::PathFindExtensionW
;
56 using ATL::PathFindFileName
;
58 #define CSIDL_LOCAL_APPDATA CSIDL_APPDATA
59 #define SHGFP_TYPE_CURRENT 0
60 #define SHGetFolderPath SHGetFolderPathW
62 // Windows Mobile doesn't provide _beginthreadex or _beginthread. Note that
63 // unlike on the desktop, CreateThread for WinCE does support the CRT.
64 inline uintptr_t _beginthreadex(void *security
,
66 unsigned (*start_address
)(void*),
70 return reinterpret_cast<uintptr_t>(CreateThread(
71 reinterpret_cast<SECURITY_ATTRIBUTES
*>(security
),
73 reinterpret_cast<DWORD (*)(void*)>(start_address
),
76 reinterpret_cast<DWORD
*>(thrdaddr
)));
79 void GetSystemTimeAsFileTime(LPFILETIME filetime
);
81 DWORD
GetShortPathNameW(LPCTSTR path_long
,
83 DWORD path_short_max_size
);
85 int SHCreateDirectoryEx(HWND window
,
87 const SECURITY_ATTRIBUTES
*security_attributes
);
89 HRESULT
SHGetFolderPathW(HWND hwndOwner
,
95 BOOL
IsNetworkAlive(LPDWORD lpdwFlags
);
97 class CMutexWince
: public ATL::CMutex
{
99 // CMutex::Open() in atlsync.h is #ifdef-ed out presumably
100 // due to the (bizarre) lack of OpenMutex() win32 API in Windows Mobile.
101 BOOL
Open(DWORD dwAccess
, BOOL bInheritHandle
, LPCTSTR pszName
);
103 static HANDLE global_mutex_
;
104 static CriticalSection lock_
;
107 #endif // GEARS_BASE_COMMON_WINCE_COMPATIBILITY_H__