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