Win32ApiSharedEmulation.h
4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#pragma once
#if IL2CPP_TARGET_WINRT || IL2CPP_TARGET_XBOXONE
#include "os/Win32/WindowsHeaders.h"
#include <wrl.h>
#if WINDOWS_SDK_BUILD_VERSION < 16299 // This got readded on Windows 10 Fall Creators Update
#define MAX_COMPUTERNAME_LENGTH 31
#define GetComputerName GetComputerNameW
#endif
namespace il2cpp
{
namespace winrt
{
inline DWORD WIN32_FROM_HRESULT(HRESULT hr)
{
if ((hr & 0xFFFF0000) == MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, 0))
return HRESULT_CODE(hr);
if (hr == S_OK)
return HRESULT_CODE(hr);
return ERROR_SUCCESS;
}
inline static BOOL CopyHStringToBuffer(Microsoft::WRL::Wrappers::HString& source, LPWSTR target, LPDWORD targetSize)
{
unsigned int sourceLength;
auto sourceBuffer = source.GetRawBuffer(&sourceLength);
if (sourceLength + 1 > *targetSize)
{
SetLastError(ERROR_BUFFER_OVERFLOW);
*targetSize = sourceLength + 1;
return FALSE;
}
*targetSize = sourceLength;
if (target != nullptr)
{
memcpy(target, sourceBuffer, sourceLength * sizeof(wchar_t));
target[sourceLength] = L'\0';
return TRUE;
}
return FALSE;
}
}
}
#if WINDOWS_SDK_BUILD_VERSION < 16299 // These APIs got readded on Windows 10 Fall Creators Update
extern "C"
{
inline BOOL WINAPI CopyFileW(LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName, BOOL bFailIfExists)
{
COPYFILE2_EXTENDED_PARAMETERS params;
params.dwSize = sizeof(params);
params.dwCopyFlags = bFailIfExists ? COPY_FILE_FAIL_IF_EXISTS : 0;
params.pfCancel = FALSE;
params.pProgressRoutine = nullptr;
params.pvCallbackContext = nullptr;
auto hr = CopyFile2(lpExistingFileName, lpNewFileName, ¶ms);
if (FAILED(hr))
{
SetLastError(il2cpp::winrt::WIN32_FROM_HRESULT(hr));
return FALSE;
}
return TRUE;
}
inline UINT WINAPI GetACP()
{
return CP_ACP;
}
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD nSize);
} // extern "C"
#endif
#if WINDOWS_SDK_BUILD_VERSION < 15063
extern "C"
{
typedef struct
{
char String[4 * 4];
} IP_ADDRESS_STRING, *PIP_ADDRESS_STRING, IP_MASK_STRING, *PIP_MASK_STRING;
typedef struct _IP_ADDR_STRING
{
struct _IP_ADDR_STRING* Next;
IP_ADDRESS_STRING IpAddress;
IP_MASK_STRING IpMask;
DWORD Context;
} IP_ADDR_STRING, *PIP_ADDR_STRING;
#define MAX_HOSTNAME_LEN 128
#define MAX_DOMAIN_NAME_LEN 128
#define MAX_SCOPE_ID_LEN 256
typedef struct
{
char HostName[MAX_HOSTNAME_LEN + 4];
char DomainName[MAX_DOMAIN_NAME_LEN + 4];
PIP_ADDR_STRING CurrentDnsServer;
IP_ADDR_STRING DnsServerList;
UINT NodeType;
char ScopeId[MAX_SCOPE_ID_LEN + 4];
UINT EnableRouting;
UINT EnableProxy;
UINT EnableDns;
} FIXED_INFO, *PFIXED_INFO;
DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen);
} // extern "C"
#endif
#if IL2CPP_TARGET_WINRT
extern "C"
{
#if WINDOWS_SDK_BUILD_VERSION < 15063
#define MAX_INTERFACE_NAME_LEN 256
#define MAXLEN_PHYSADDR 8
typedef enum
{
IF_OPER_STATUS_NON_OPERATIONAL = 0,
IF_OPER_STATUS_UNREACHABLE = 1,
IF_OPER_STATUS_DISCONNECTED = 2,
IF_OPER_STATUS_CONNECTING = 3,
IF_OPER_STATUS_CONNECTED = 4,
IF_OPER_STATUS_OPERATIONAL = 5,
} INTERNAL_IF_OPER_STATUS;
#define MAXLEN_IFDESCR 256
typedef struct
{
WCHAR wszName[MAX_INTERFACE_NAME_LEN];
IF_INDEX dwIndex;
IFTYPE dwType;
DWORD dwMtu;
DWORD dwSpeed;
DWORD dwPhysAddrLen;
UCHAR bPhysAddr[MAXLEN_PHYSADDR];
DWORD dwAdminStatus;
INTERNAL_IF_OPER_STATUS dwOperStatus;
DWORD dwLastChange;
DWORD dwInOctets;
DWORD dwInUcastPkts;
DWORD dwInNUcastPkts;
DWORD dwInDiscards;
DWORD dwInErrors;
DWORD dwInUnknownProtos;
DWORD dwOutOctets;
DWORD dwOutUcastPkts;
DWORD dwOutNUcastPkts;
DWORD dwOutDiscards;
DWORD dwOutErrors;
DWORD dwOutQLen;
DWORD dwDescrLen;
UCHAR bDescr[MAXLEN_IFDESCR];
} MIB_IFROW, *PMIB_IFROW;
#endif
DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow);
} // extern "C"
#endif // IL2CPP_TARGET_WINRT
#endif