Win32ApiSharedEmulation.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #pragma once
  2. #if IL2CPP_TARGET_WINRT || IL2CPP_TARGET_XBOXONE
  3. #include "os/Win32/WindowsHeaders.h"
  4. #include <wrl.h>
  5. #if WINDOWS_SDK_BUILD_VERSION < 16299 // This got readded on Windows 10 Fall Creators Update
  6. #define MAX_COMPUTERNAME_LENGTH 31
  7. #define GetComputerName GetComputerNameW
  8. #endif
  9. namespace il2cpp
  10. {
  11. namespace winrt
  12. {
  13. inline DWORD WIN32_FROM_HRESULT(HRESULT hr)
  14. {
  15. if ((hr & 0xFFFF0000) == MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, 0))
  16. return HRESULT_CODE(hr);
  17. if (hr == S_OK)
  18. return HRESULT_CODE(hr);
  19. return ERROR_SUCCESS;
  20. }
  21. inline static BOOL CopyHStringToBuffer(Microsoft::WRL::Wrappers::HString& source, LPWSTR target, LPDWORD targetSize)
  22. {
  23. unsigned int sourceLength;
  24. auto sourceBuffer = source.GetRawBuffer(&sourceLength);
  25. if (sourceLength + 1 > *targetSize)
  26. {
  27. SetLastError(ERROR_BUFFER_OVERFLOW);
  28. *targetSize = sourceLength + 1;
  29. return FALSE;
  30. }
  31. *targetSize = sourceLength;
  32. if (target != nullptr)
  33. {
  34. memcpy(target, sourceBuffer, sourceLength * sizeof(wchar_t));
  35. target[sourceLength] = L'\0';
  36. return TRUE;
  37. }
  38. return FALSE;
  39. }
  40. }
  41. }
  42. #if WINDOWS_SDK_BUILD_VERSION < 16299 // These APIs got readded on Windows 10 Fall Creators Update
  43. extern "C"
  44. {
  45. inline BOOL WINAPI CopyFileW(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName, BOOL bFailIfExists)
  46. {
  47. COPYFILE2_EXTENDED_PARAMETERS params;
  48. params.dwSize = sizeof(params);
  49. params.dwCopyFlags = bFailIfExists ? COPY_FILE_FAIL_IF_EXISTS : 0;
  50. params.pfCancel = FALSE;
  51. params.pProgressRoutine = nullptr;
  52. params.pvCallbackContext = nullptr;
  53. auto hr = CopyFile2(lpExistingFileName, lpNewFileName, &params);
  54. if (FAILED(hr))
  55. {
  56. SetLastError(il2cpp::winrt::WIN32_FROM_HRESULT(hr));
  57. return FALSE;
  58. }
  59. return TRUE;
  60. }
  61. inline UINT WINAPI GetACP()
  62. {
  63. return CP_ACP;
  64. }
  65. BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD nSize);
  66. } // extern "C"
  67. #endif
  68. #if WINDOWS_SDK_BUILD_VERSION < 15063
  69. extern "C"
  70. {
  71. typedef struct
  72. {
  73. char String[4 * 4];
  74. } IP_ADDRESS_STRING, *PIP_ADDRESS_STRING, IP_MASK_STRING, *PIP_MASK_STRING;
  75. typedef struct _IP_ADDR_STRING
  76. {
  77. struct _IP_ADDR_STRING* Next;
  78. IP_ADDRESS_STRING IpAddress;
  79. IP_MASK_STRING IpMask;
  80. DWORD Context;
  81. } IP_ADDR_STRING, *PIP_ADDR_STRING;
  82. #define MAX_HOSTNAME_LEN 128
  83. #define MAX_DOMAIN_NAME_LEN 128
  84. #define MAX_SCOPE_ID_LEN 256
  85. typedef struct
  86. {
  87. char HostName[MAX_HOSTNAME_LEN + 4];
  88. char DomainName[MAX_DOMAIN_NAME_LEN + 4];
  89. PIP_ADDR_STRING CurrentDnsServer;
  90. IP_ADDR_STRING DnsServerList;
  91. UINT NodeType;
  92. char ScopeId[MAX_SCOPE_ID_LEN + 4];
  93. UINT EnableRouting;
  94. UINT EnableProxy;
  95. UINT EnableDns;
  96. } FIXED_INFO, *PFIXED_INFO;
  97. DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen);
  98. } // extern "C"
  99. #endif
  100. #endif