#include "il2cpp-config.h" #if IL2CPP_TARGET_WINDOWS && !IL2CPP_USE_GENERIC_WINDOWSRUNTIME #include "il2cpp-class-internals.h" #include "il2cpp-string-types.h" #include "os/WindowsRuntime.h" #include "utils/Expected.h" #include "utils/Il2CppError.h" #include "utils/StringUtils.h" #include "vm/CCW.h" #include "WindowsHeaders.h" #include namespace il2cpp { namespace os { il2cpp_hresult_t WindowsRuntime::GetActivationFactory(Il2CppHString className, Il2CppIActivationFactory** activationFactory) { IL2CPP_ASSERT(className != NULL); IL2CPP_ASSERT(activationFactory != NULL); return RoGetActivationFactory(reinterpret_cast(className), reinterpret_cast(Il2CppIActivationFactory::IID), reinterpret_cast(activationFactory)); } il2cpp_hresult_t WindowsRuntime::CreateHStringReference(const utils::StringView& str, Il2CppHStringHeader* header, Il2CppHString* hstring) { IL2CPP_ASSERT(header != NULL); IL2CPP_ASSERT(hstring != NULL); if (str.Length() == 0) { *hstring = NULL; return S_OK; } return WindowsCreateStringReference(str.Str(), static_cast(str.Length()), reinterpret_cast(header), reinterpret_cast(hstring)); } il2cpp_hresult_t WindowsRuntime::CreateHString(const utils::StringView& str, Il2CppHString* hstring) { IL2CPP_ASSERT(str.Str() != NULL || str.Length() == 0); if (str.Length() == 0) { *hstring = NULL; return S_OK; } return WindowsCreateString(str.Str(), static_cast(str.Length()), reinterpret_cast(hstring)); } il2cpp_hresult_t WindowsRuntime::DuplicateHString(Il2CppHString hstring, Il2CppHString* duplicated) { return WindowsDuplicateString(reinterpret_cast(hstring), reinterpret_cast(duplicated)); } il2cpp_hresult_t WindowsRuntime::DeleteHString(Il2CppHString hstring) { if (hstring == NULL) return IL2CPP_S_OK; return WindowsDeleteString(reinterpret_cast(hstring)); } utils::Expected WindowsRuntime::GetHStringBuffer(Il2CppHString hstring, uint32_t* length) { return WindowsGetStringRawBuffer(reinterpret_cast(hstring), length); } utils::Expected WindowsRuntime::GetNativeHStringBuffer(Il2CppHString hstring, uint32_t* length) { return GetHStringBuffer(hstring, length); } utils::Expected WindowsRuntime::PreallocateHStringBuffer(uint32_t length, Il2CppNativeChar** mutableBuffer, void** bufferHandle) { return WindowsPreallocateStringBuffer(length, mutableBuffer, reinterpret_cast(bufferHandle)); } utils::Expected WindowsRuntime::PromoteHStringBuffer(void* bufferHandle, Il2CppHString* hstring) { return WindowsPromoteStringBuffer(static_cast(bufferHandle), reinterpret_cast(hstring)); } utils::Expected WindowsRuntime::DeleteHStringBuffer(void* bufferHandle) { return WindowsDeleteStringBuffer(static_cast(bufferHandle)); } Il2CppIRestrictedErrorInfo* WindowsRuntime::GetRestrictedErrorInfo() { Il2CppIRestrictedErrorInfo* errorInfo; HRESULT hr; hr = ::GetRestrictedErrorInfo(reinterpret_cast(&errorInfo)); if (FAILED(hr)) return NULL; return errorInfo; } void WindowsRuntime::OriginateLanguageException(il2cpp_hresult_t hresult, Il2CppException* ex, Il2CppString* exceptionString, GetOrCreateFunc createCCWCallback) { utils::StringView message(utils::StringUtils::GetChars(exceptionString), utils::StringUtils::GetLength(exceptionString)); Il2CppHString messageHString; Il2CppHStringHeader unused; CreateHStringReference(message, &unused, &messageHString); Il2CppIUnknown* exceptionCCW = createCCWCallback(reinterpret_cast(ex), Il2CppIUnknown::IID); RoOriginateLanguageException(hresult, reinterpret_cast(messageHString), reinterpret_cast(exceptionCCW)); exceptionCCW->Release(); } void WindowsRuntime::EnableErrorReporting() { il2cpp_hresult_t hr = RoSetErrorReportingFlags(RO_ERROR_REPORTING_USESETERRORINFO); IL2CPP_ASSERT(IL2CPP_HR_SUCCEEDED(hr) && "RoSetErrorReportingFlags failed"); } } } #endif