foobar2000 SDK  2015-08-03
pp-winapi.h
Go to the documentation of this file.
1 #if !defined(PP_WINAPI_H_INCLUDED) && defined(_WIN32)
2 #define PP_WINAPI_H_INCLUDED
3 
4 #ifdef WINAPI_FAMILY_PARTITION
5 
6 #if ! WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
7 
8 inline HANDLE CreateEvent(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCTSTR lpName) {
9  DWORD flags = 0;
10  if (bManualReset) flags |= CREATE_EVENT_MANUAL_RESET;
11  if (bInitialState) flags |= CREATE_EVENT_INITIAL_SET;
12  DWORD rights = SYNCHRONIZE | EVENT_MODIFY_STATE;
13  return CreateEventEx(lpEventAttributes, lpName, flags, rights);
14 }
15 
16 inline DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds) {
17  return WaitForSingleObjectEx(hHandle, dwMilliseconds, FALSE);
18 }
19 
20 inline DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAll, DWORD dwMilliseconds) {
21  return WaitForMultipleObjectsEx(nCount, lpHandles, bWaitAll, dwMilliseconds, FALSE);
22 }
23 
24 inline void InitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection) {
25  InitializeCriticalSectionEx(lpCriticalSection, 0, 0);
26 }
27 
28 inline HANDLE FindFirstFile(LPCTSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData) {
29  return FindFirstFileEx(lpFileName, FindExInfoStandard, lpFindFileData, FindExSearchNameMatch, NULL, 0);
30 }
31 
32 inline BOOL GetFileSizeEx(HANDLE hFile, PLARGE_INTEGER lpFileSize) {
33  FILE_STANDARD_INFO info;
34  if (!GetFileInformationByHandleEx(hFile, FileStandardInfo, &info, sizeof(info))) return FALSE;
35  *lpFileSize = info.EndOfFile;
36  return TRUE;
37 }
38 
39 inline HANDLE CreateFileW(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) {
40  CREATEFILE2_EXTENDED_PARAMETERS arg = {};
41  arg.dwSize = sizeof(arg);
42  arg.hTemplateFile = hTemplateFile;
43  arg.lpSecurityAttributes = lpSecurityAttributes;
44  arg.dwFileAttributes = dwFlagsAndAttributes & 0x0000FFFF;
45  arg.dwFileFlags = dwFlagsAndAttributes & 0xFFFF0000;
46  return CreateFile2(lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition, &arg);
47 }
48 
49 inline DWORD GetFileAttributesW(const wchar_t * path) {
50  WIN32_FILE_ATTRIBUTE_DATA data = {};
51  if (!GetFileAttributesEx(path, GetFileExInfoStandard, &data)) return 0xFFFFFFFF;
52  return data.dwFileAttributes;
53 }
54 
55 #define GetFileAttributes GetFileAttributesW
56 
57 #endif // #if ! WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
58 
59 #endif // #ifdef WINAPI_FAMILY_PARTITION
60 
61 #endif // !defined(PP_WINAPI_H_INCLUDED) && defined(_WIN32)
DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAll, DWORD dwMilliseconds)
Definition: pp-winapi.h:20
DWORD GetFileAttributesW(const wchar_t *path)
Definition: pp-winapi.h:49
HANDLE CreateFileW(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
Definition: pp-winapi.h:39
void info(const char *p_message)
Definition: console.cpp:4
typedef BOOL(WINAPI *pPowerSetRequest_t)(__in HANDLE PowerRequest
typedef HANDLE(WINAPI *pPowerCreateRequest_t)(__in void *Context)
BOOL GetFileSizeEx(HANDLE hFile, PLARGE_INTEGER lpFileSize)
Definition: pp-winapi.h:32
DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
Definition: pp-winapi.h:16
void InitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
Definition: pp-winapi.h:24
HANDLE FindFirstFile(LPCTSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData)
Definition: pp-winapi.h:28
HANDLE CreateEvent(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCTSTR lpName)
Definition: pp-winapi.h:8