Win32ApiSharedEmulation.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. #if IL2CPP_TARGET_WINRT
  101. extern "C"
  102. {
  103. #if WINDOWS_SDK_BUILD_VERSION < 15063
  104. #define MAX_INTERFACE_NAME_LEN 256
  105. #define MAXLEN_PHYSADDR 8
  106. typedef enum
  107. {
  108. IF_OPER_STATUS_NON_OPERATIONAL = 0,
  109. IF_OPER_STATUS_UNREACHABLE = 1,
  110. IF_OPER_STATUS_DISCONNECTED = 2,
  111. IF_OPER_STATUS_CONNECTING = 3,
  112. IF_OPER_STATUS_CONNECTED = 4,
  113. IF_OPER_STATUS_OPERATIONAL = 5,
  114. } INTERNAL_IF_OPER_STATUS;
  115. #define MAXLEN_IFDESCR 256
  116. typedef struct
  117. {
  118. WCHAR wszName[MAX_INTERFACE_NAME_LEN];
  119. IF_INDEX dwIndex;
  120. IFTYPE dwType;
  121. DWORD dwMtu;
  122. DWORD dwSpeed;
  123. DWORD dwPhysAddrLen;
  124. UCHAR bPhysAddr[MAXLEN_PHYSADDR];
  125. DWORD dwAdminStatus;
  126. INTERNAL_IF_OPER_STATUS dwOperStatus;
  127. DWORD dwLastChange;
  128. DWORD dwInOctets;
  129. DWORD dwInUcastPkts;
  130. DWORD dwInNUcastPkts;
  131. DWORD dwInDiscards;
  132. DWORD dwInErrors;
  133. DWORD dwInUnknownProtos;
  134. DWORD dwOutOctets;
  135. DWORD dwOutUcastPkts;
  136. DWORD dwOutNUcastPkts;
  137. DWORD dwOutDiscards;
  138. DWORD dwOutErrors;
  139. DWORD dwOutQLen;
  140. DWORD dwDescrLen;
  141. UCHAR bDescr[MAXLEN_IFDESCR];
  142. } MIB_IFROW, *PMIB_IFROW;
  143. #endif
  144. DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow);
  145. } // extern "C"
  146. #endif // IL2CPP_TARGET_WINRT
  147. #endif