Win32ApiWinRTEmulation.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #pragma once
  2. #if IL2CPP_TARGET_WINRT
  3. extern "C"
  4. {
  5. #if WINDOWS_SDK_BUILD_VERSION < 16299 // These APIs got readded on Windows 10 Fall Creators Update
  6. #define CreateEvent CreateEventW
  7. #define FreeEnvironmentStrings FreeEnvironmentStringsW
  8. #define GetEnvironmentStrings GetEnvironmentStringsW
  9. #define GetEnvironmentVariable GetEnvironmentVariableW
  10. #define GetVersionEx GetVersionExW
  11. #define SetEnvironmentVariable SetEnvironmentVariableW
  12. #endif
  13. #define GetUserName GetUserNameW
  14. #if WINDOWS_SDK_BUILD_VERSION < 16299
  15. inline HANDLE WINAPI CreateEventW(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCWSTR lpName)
  16. {
  17. DWORD flags = 0;
  18. if (bManualReset)
  19. flags |= CREATE_EVENT_MANUAL_RESET;
  20. if (bInitialState)
  21. flags |= CREATE_EVENT_INITIAL_SET;
  22. return CreateEventExW(lpEventAttributes, lpName, flags, EVENT_ALL_ACCESS);
  23. }
  24. #endif
  25. inline HANDLE WINAPI CreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
  26. {
  27. const DWORD kFileAttributeMask = 0x0000FFFF;
  28. const DWORD kFileFlagMask = 0xFFFF0000;
  29. CREATEFILE2_EXTENDED_PARAMETERS extendedParameters;
  30. extendedParameters.dwSize = sizeof(CREATEFILE2_EXTENDED_PARAMETERS);
  31. extendedParameters.dwFileAttributes = dwFlagsAndAttributes & kFileAttributeMask;
  32. extendedParameters.dwFileFlags = dwFlagsAndAttributes & kFileFlagMask;
  33. extendedParameters.dwSecurityQosFlags = SECURITY_ANONYMOUS;
  34. extendedParameters.lpSecurityAttributes = lpSecurityAttributes;
  35. extendedParameters.hTemplateFile = hTemplateFile;
  36. return CreateFile2(lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition, &extendedParameters);
  37. }
  38. #if WINDOWS_SDK_BUILD_VERSION < 16299
  39. BOOL WINAPI FreeEnvironmentStringsW(LPWCH strings);
  40. LPWCH WINAPI GetEnvironmentStringsW();
  41. DWORD WINAPI GetEnvironmentVariableW(LPCWSTR lpName, LPWSTR lpBuffer, DWORD nSize);
  42. BOOL WINAPI GetVersionExW(LPOSVERSIONINFOW lpVersionInformation);
  43. #endif
  44. BOOL WINAPI GetUserNameW(LPWSTR lpBuffer, LPDWORD pcbBuffer);
  45. inline HMODULE WINAPI LoadLibraryW(LPCWSTR lpLibFileName)
  46. {
  47. return LoadPackagedLibrary(lpLibFileName, 0);
  48. }
  49. #if WINDOWS_SDK_BUILD_VERSION < 16299
  50. BOOL WINAPI SetEnvironmentVariableW(LPCWSTR lpName, LPCWSTR lpValue);
  51. #endif
  52. #define CreateFileMappingW(hFile, lpFileMappingAttributes, flProtect, dwMaximumSizeHigh, dwMaximumSizeLow, lpName) \
  53. CreateFileMappingFromApp(hFile, lpFileMappingAttributes, flProtect, (static_cast<ULONG64>(dwMaximumSizeHigh) << 32) | dwMaximumSizeLow, lpName);
  54. #define MapViewOfFile(hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh, dwFileOffsetLow, dwNumberOfBytesToMap) \
  55. MapViewOfFileFromApp(hFileMappingObject, dwDesiredAccess, (static_cast<ULONG64>(dwFileOffsetHigh) << 32) | dwFileOffsetLow, dwNumberOfBytesToMap);
  56. #define TlsAlloc() FlsAlloc(NULL)
  57. #define TlsGetValue FlsGetValue
  58. #define TlsSetValue FlsSetValue
  59. #define TlsFree FlsFree
  60. } // extern "C"
  61. #endif