Initial commit.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include "os/Win32/WindowsHeaders.h"
|
||||
#include <windows.foundation.collections.h>
|
||||
#include <wrl.h>
|
||||
|
||||
namespace il2cpp
|
||||
{
|
||||
namespace winrt
|
||||
{
|
||||
template<typename T>
|
||||
class SynchronousOperation : Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::WinRtClassicComMix>, ABI::Windows::Foundation::IAsyncOperationCompletedHandler<T> >
|
||||
{
|
||||
private:
|
||||
HANDLE m_Event;
|
||||
HRESULT m_HR;
|
||||
T m_Result;
|
||||
|
||||
public:
|
||||
inline SynchronousOperation(ABI::Windows::Foundation::IAsyncOperation<T>* op)
|
||||
{
|
||||
m_Event = CreateEventExW(nullptr, nullptr, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS);
|
||||
Assert(m_Event);
|
||||
|
||||
auto hr = op->put_Completed(this);
|
||||
Assert(SUCCEEDED(hr));
|
||||
}
|
||||
|
||||
inline ~SynchronousOperation()
|
||||
{
|
||||
CloseHandle(m_Event);
|
||||
}
|
||||
|
||||
HRESULT GetResults(T* result)
|
||||
{
|
||||
auto waitResult = WaitForSingleObjectEx(m_Event, INFINITE, FALSE);
|
||||
|
||||
if (waitResult != WAIT_OBJECT_0)
|
||||
return E_FAIL;
|
||||
|
||||
if (FAILED(m_HR))
|
||||
return m_HR;
|
||||
|
||||
*result = m_Result;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual HRESULT STDMETHODCALLTYPE Invoke(ABI::Windows::Foundation::IAsyncOperation<T>* asyncInfo, ABI::Windows::Foundation::AsyncStatus status) override
|
||||
{
|
||||
m_HR = asyncInfo->GetResults(&m_Result);
|
||||
SetEvent(m_Event);
|
||||
return S_OK;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
#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
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,89 @@
|
||||
#pragma once
|
||||
|
||||
#if IL2CPP_TARGET_WINRT
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#if WINDOWS_SDK_BUILD_VERSION < 16299 // These APIs got readded on Windows 10 Fall Creators Update
|
||||
|
||||
#define CreateEvent CreateEventW
|
||||
#define FreeEnvironmentStrings FreeEnvironmentStringsW
|
||||
#define GetEnvironmentStrings GetEnvironmentStringsW
|
||||
#define GetEnvironmentVariable GetEnvironmentVariableW
|
||||
#define GetVersionEx GetVersionExW
|
||||
#define SetEnvironmentVariable SetEnvironmentVariableW
|
||||
|
||||
#endif
|
||||
|
||||
#define GetUserName GetUserNameW
|
||||
|
||||
#if WINDOWS_SDK_BUILD_VERSION < 16299
|
||||
|
||||
inline HANDLE WINAPI CreateEventW(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCWSTR lpName)
|
||||
{
|
||||
DWORD flags = 0;
|
||||
if (bManualReset)
|
||||
flags |= CREATE_EVENT_MANUAL_RESET;
|
||||
if (bInitialState)
|
||||
flags |= CREATE_EVENT_INITIAL_SET;
|
||||
return CreateEventExW(lpEventAttributes, lpName, flags, EVENT_ALL_ACCESS);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
inline HANDLE WINAPI CreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
|
||||
{
|
||||
const DWORD kFileAttributeMask = 0x0000FFFF;
|
||||
const DWORD kFileFlagMask = 0xFFFF0000;
|
||||
|
||||
CREATEFILE2_EXTENDED_PARAMETERS extendedParameters;
|
||||
extendedParameters.dwSize = sizeof(CREATEFILE2_EXTENDED_PARAMETERS);
|
||||
extendedParameters.dwFileAttributes = dwFlagsAndAttributes & kFileAttributeMask;
|
||||
extendedParameters.dwFileFlags = dwFlagsAndAttributes & kFileFlagMask;
|
||||
extendedParameters.dwSecurityQosFlags = SECURITY_ANONYMOUS;
|
||||
extendedParameters.lpSecurityAttributes = lpSecurityAttributes;
|
||||
extendedParameters.hTemplateFile = hTemplateFile;
|
||||
|
||||
return CreateFile2(lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition, &extendedParameters);
|
||||
}
|
||||
|
||||
#if WINDOWS_SDK_BUILD_VERSION < 16299
|
||||
|
||||
BOOL WINAPI FreeEnvironmentStringsW(LPWCH strings);
|
||||
|
||||
LPWCH WINAPI GetEnvironmentStringsW();
|
||||
|
||||
DWORD WINAPI GetEnvironmentVariableW(LPCWSTR lpName, LPWSTR lpBuffer, DWORD nSize);
|
||||
|
||||
BOOL WINAPI GetVersionExW(LPOSVERSIONINFOW lpVersionInformation);
|
||||
|
||||
#endif
|
||||
|
||||
BOOL WINAPI GetUserNameW(LPWSTR lpBuffer, LPDWORD pcbBuffer);
|
||||
|
||||
inline HMODULE WINAPI LoadLibraryW(LPCWSTR lpLibFileName)
|
||||
{
|
||||
return LoadPackagedLibrary(lpLibFileName, 0);
|
||||
}
|
||||
|
||||
#if WINDOWS_SDK_BUILD_VERSION < 16299
|
||||
|
||||
BOOL WINAPI SetEnvironmentVariableW(LPCWSTR lpName, LPCWSTR lpValue);
|
||||
|
||||
#endif
|
||||
|
||||
#define CreateFileMappingW(hFile, lpFileMappingAttributes, flProtect, dwMaximumSizeHigh, dwMaximumSizeLow, lpName) \
|
||||
CreateFileMappingFromApp(hFile, lpFileMappingAttributes, flProtect, (static_cast<ULONG64>(dwMaximumSizeHigh) << 32) | dwMaximumSizeLow, lpName);
|
||||
|
||||
#define MapViewOfFile(hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh, dwFileOffsetLow, dwNumberOfBytesToMap) \
|
||||
MapViewOfFileFromApp(hFileMappingObject, dwDesiredAccess, (static_cast<ULONG64>(dwFileOffsetHigh) << 32) | dwFileOffsetLow, dwNumberOfBytesToMap);
|
||||
|
||||
#if WINDOWS_SDK_BUILD_VERSION < 14393
|
||||
#define TlsAlloc() FlsAlloc(NULL)
|
||||
#define TlsGetValue FlsGetValue
|
||||
#define TlsSetValue FlsSetValue
|
||||
#define TlsFree FlsFree
|
||||
#endif
|
||||
} // extern "C"
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user