1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // This file contains defines and typedefs that allow popular Windows types to 6 // be used without the overhead of including windows.h. 7 8 #ifndef BASE_WIN_WINDOWS_TYPES_H 9 #define BASE_WIN_WINDOWS_TYPES_H 10 11 // Needed for function prototypes. 12 #if defined(__MINGW32__) 13 // MinGW doesn't have this file yet, but we only need this define. 14 // Bug 1552706 tracks removing this and the one below. 15 #define _Releases_exclusive_lock_(lock) 16 // MinGW doesn't appear to have this in specstrings.h either. 17 #define _Post_equals_last_error_ 18 #else 19 #include <concurrencysal.h> 20 #endif 21 #include <sal.h> 22 #include <specstrings.h> 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 // typedef and define the most commonly used Windows integer types. 29 30 typedef unsigned long DWORD; 31 typedef long LONG; 32 typedef __int64 LONGLONG; 33 typedef unsigned __int64 ULONGLONG; 34 35 #define VOID void 36 typedef char CHAR; 37 typedef short SHORT; 38 typedef long LONG; 39 typedef int INT; 40 typedef unsigned int UINT; 41 typedef unsigned int* PUINT; 42 typedef void* LPVOID; 43 typedef void* PVOID; 44 typedef void* HANDLE; 45 typedef int BOOL; 46 typedef unsigned char BYTE; 47 typedef BYTE BOOLEAN; 48 typedef DWORD ULONG; 49 typedef unsigned short WORD; 50 typedef WORD UWORD; 51 typedef WORD ATOM; 52 53 #if defined(_WIN64) 54 typedef __int64 INT_PTR, *PINT_PTR; 55 typedef unsigned __int64 UINT_PTR, *PUINT_PTR; 56 57 typedef __int64 LONG_PTR, *PLONG_PTR; 58 typedef unsigned __int64 ULONG_PTR, *PULONG_PTR; 59 #else 60 typedef __w64 int INT_PTR, *PINT_PTR; 61 typedef __w64 unsigned int UINT_PTR, *PUINT_PTR; 62 63 typedef __w64 long LONG_PTR, *PLONG_PTR; 64 typedef __w64 unsigned long ULONG_PTR, *PULONG_PTR; 65 #endif 66 67 typedef UINT_PTR WPARAM; 68 typedef LONG_PTR LPARAM; 69 typedef LONG_PTR LRESULT; 70 #define LRESULT LONG_PTR 71 typedef _Return_type_success_(return >= 0) long HRESULT; 72 73 typedef ULONG_PTR SIZE_T, *PSIZE_T; 74 typedef LONG_PTR SSIZE_T, *PSSIZE_T; 75 76 typedef DWORD ACCESS_MASK; 77 typedef ACCESS_MASK REGSAM; 78 79 // As defined in guiddef.h. 80 #ifndef _REFGUID_DEFINED 81 #define _REFGUID_DEFINED 82 #define REFGUID const GUID& 83 #endif 84 85 // Forward declare Windows compatible handles. 86 87 #define CHROME_DECLARE_HANDLE(name) \ 88 struct name##__; \ 89 typedef struct name##__* name 90 CHROME_DECLARE_HANDLE(HDESK); 91 CHROME_DECLARE_HANDLE(HGLRC); 92 CHROME_DECLARE_HANDLE(HICON); 93 CHROME_DECLARE_HANDLE(HINSTANCE); 94 CHROME_DECLARE_HANDLE(HKEY); 95 CHROME_DECLARE_HANDLE(HKL); 96 CHROME_DECLARE_HANDLE(HMENU); 97 CHROME_DECLARE_HANDLE(HWINSTA); 98 CHROME_DECLARE_HANDLE(HWND); 99 #undef CHROME_DECLARE_HANDLE 100 101 typedef LPVOID HINTERNET; 102 typedef HINSTANCE HMODULE; 103 typedef PVOID LSA_HANDLE; 104 105 // Forward declare some Windows struct/typedef sets. 106 107 typedef struct _OVERLAPPED OVERLAPPED; 108 typedef struct tagMSG MSG, *PMSG, *NPMSG, *LPMSG; 109 110 typedef struct _RTL_SRWLOCK RTL_SRWLOCK; 111 typedef RTL_SRWLOCK SRWLOCK, *PSRWLOCK; 112 113 typedef struct _GUID GUID; 114 typedef GUID CLSID; 115 116 typedef struct tagLOGFONTW LOGFONTW, *PLOGFONTW, *NPLOGFONTW, *LPLOGFONTW; 117 typedef LOGFONTW LOGFONT; 118 119 typedef struct _FILETIME FILETIME; 120 121 typedef struct tagMENUITEMINFOW MENUITEMINFOW, MENUITEMINFO; 122 123 typedef struct tagNMHDR NMHDR; 124 125 typedef PVOID PSID; 126 127 // Declare Chrome versions of some Windows structures. These are needed for 128 // when we need a concrete type but don't want to pull in Windows.h. We can't 129 // declare the Windows types so we declare our types and cast to the Windows 130 // types in a few places. 131 132 struct CHROME_SRWLOCK { 133 PVOID Ptr; 134 }; 135 136 struct CHROME_CONDITION_VARIABLE { 137 PVOID Ptr; 138 }; 139 140 // Define some commonly used Windows constants. Note that the layout of these 141 // macros - including internal spacing - must be 100% consistent with windows.h. 142 143 // clang-format off 144 145 #ifndef INVALID_HANDLE_VALUE 146 // Work around there being two slightly different definitions in the SDK. 147 #define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1) 148 #endif 149 #define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF) 150 #define HTNOWHERE 0 151 #define MAX_PATH 260 152 #define CS_GLOBALCLASS 0x4000 153 154 #define ERROR_SUCCESS 0L 155 #define ERROR_FILE_NOT_FOUND 2L 156 #define ERROR_ACCESS_DENIED 5L 157 #define ERROR_INVALID_HANDLE 6L 158 #define ERROR_SHARING_VIOLATION 32L 159 #define ERROR_LOCK_VIOLATION 33L 160 #define REG_BINARY ( 3ul ) 161 162 #define STATUS_PENDING ((DWORD )0x00000103L) 163 #define STILL_ACTIVE STATUS_PENDING 164 #define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0) 165 #define FAILED(hr) (((HRESULT)(hr)) < 0) 166 167 #define HKEY_CLASSES_ROOT (( HKEY ) (ULONG_PTR)((LONG)0x80000000) ) 168 #define HKEY_LOCAL_MACHINE (( HKEY ) (ULONG_PTR)((LONG)0x80000002) ) 169 #define HKEY_CURRENT_USER (( HKEY ) (ULONG_PTR)((LONG)0x80000001) ) 170 #define KEY_QUERY_VALUE (0x0001) 171 #define KEY_SET_VALUE (0x0002) 172 #define KEY_CREATE_SUB_KEY (0x0004) 173 #define KEY_ENUMERATE_SUB_KEYS (0x0008) 174 #define KEY_NOTIFY (0x0010) 175 #define KEY_CREATE_LINK (0x0020) 176 #define KEY_WOW64_32KEY (0x0200) 177 #define KEY_WOW64_64KEY (0x0100) 178 #define KEY_WOW64_RES (0x0300) 179 180 #define READ_CONTROL (0x00020000L) 181 #define SYNCHRONIZE (0x00100000L) 182 183 #define STANDARD_RIGHTS_READ (READ_CONTROL) 184 #define STANDARD_RIGHTS_WRITE (READ_CONTROL) 185 #define STANDARD_RIGHTS_ALL (0x001F0000L) 186 187 #define KEY_READ ((STANDARD_RIGHTS_READ |\ 188 KEY_QUERY_VALUE |\ 189 KEY_ENUMERATE_SUB_KEYS |\ 190 KEY_NOTIFY) \ 191 & \ 192 (~SYNCHRONIZE)) 193 194 195 #define KEY_WRITE ((STANDARD_RIGHTS_WRITE |\ 196 KEY_SET_VALUE |\ 197 KEY_CREATE_SUB_KEY) \ 198 & \ 199 (~SYNCHRONIZE)) 200 201 #define KEY_ALL_ACCESS ((STANDARD_RIGHTS_ALL |\ 202 KEY_QUERY_VALUE |\ 203 KEY_SET_VALUE |\ 204 KEY_CREATE_SUB_KEY |\ 205 KEY_ENUMERATE_SUB_KEYS |\ 206 KEY_NOTIFY |\ 207 KEY_CREATE_LINK) \ 208 & \ 209 (~SYNCHRONIZE)) 210 211 // clang-format on 212 213 // Define some macros needed when prototyping Windows functions. 214 215 #define DECLSPEC_IMPORT __declspec(dllimport) 216 #define WINBASEAPI DECLSPEC_IMPORT 217 #define WINUSERAPI DECLSPEC_IMPORT 218 #define WINAPI __stdcall 219 #define CALLBACK __stdcall 220 221 // Needed for optimal lock performance. 222 WINBASEAPI _Releases_exclusive_lock_(*SRWLock) VOID WINAPI 223 ReleaseSRWLockExclusive(_Inout_ PSRWLOCK SRWLock); 224 225 // Needed to support protobuf's GetMessage macro magic. 226 WINUSERAPI BOOL WINAPI GetMessageW(_Out_ LPMSG lpMsg, 227 _In_opt_ HWND hWnd, 228 _In_ UINT wMsgFilterMin, 229 _In_ UINT wMsgFilterMax); 230 231 // Needed for thread_local_storage.h 232 WINBASEAPI LPVOID WINAPI TlsGetValue(_In_ DWORD dwTlsIndex); 233 234 // Needed for scoped_handle.h 235 WINBASEAPI _Check_return_ _Post_equals_last_error_ DWORD WINAPI 236 GetLastError(VOID); 237 238 WINBASEAPI VOID WINAPI SetLastError(_In_ DWORD dwErrCode); 239 240 #ifdef __cplusplus 241 } 242 #endif 243 244 // These macros are all defined by windows.h and are also used as the names of 245 // functions in the Chromium code base. Add to this list as needed whenever 246 // there is a Windows macro which causes a function call to be renamed. This 247 // ensures that the same renaming will happen everywhere. Includes of this file 248 // can be added wherever needed to ensure this consistent renaming. 249 250 #define CopyFile CopyFileW 251 #define CreateDirectory CreateDirectoryW 252 #define CreateEvent CreateEventW 253 #define CreateFile CreateFileW 254 #define CreateService CreateServiceW 255 #define DeleteFile DeleteFileW 256 #define DispatchMessage DispatchMessageW 257 #define DrawText DrawTextW 258 #define FindFirstFile FindFirstFileW 259 #define FindNextFile FindNextFileW 260 #define GetComputerName GetComputerNameW 261 #define GetCurrentDirectory GetCurrentDirectoryW 262 #define GetCurrentTime() GetTickCount() 263 #define GetFileAttributes GetFileAttributesW 264 #define GetMessage GetMessageW 265 #define GetUserName GetUserNameW 266 #define LoadIcon LoadIconW 267 #define LoadImage LoadImageW 268 #define PostMessage PostMessageW 269 #define RemoveDirectory RemoveDirectoryW 270 #define ReplaceFile ReplaceFileW 271 #define ReportEvent ReportEventW 272 #define SendMessage SendMessageW 273 #define SendMessageCallback SendMessageCallbackW 274 #define SetCurrentDirectory SetCurrentDirectoryW 275 #define StartService StartServiceW 276 #define UpdateResource UpdateResourceW 277 278 #endif // BASE_WIN_WINDOWS_TYPES_H 279