From 6fc9afbe7ad3931a8bfcaa22b946d34f2ef18363 Mon Sep 17 00:00:00 2001 From: HIllya51 <1173718158@qq.com> Date: Mon, 3 Feb 2025 20:27:32 +0800 Subject: [PATCH] roapi for winrt --- ThunksList.md | 5 ++ src/Thunks/YY_Thunks.cpp | 1 + src/Thunks/api-ms-win-core-com.hpp | 32 ++++++- src/Thunks/api-ms-win-core-winrt-error.hpp | 100 ++++++++++++++++++++- 4 files changed, 136 insertions(+), 2 deletions(-) diff --git a/ThunksList.md b/ThunksList.md index dc5a694..4ace4d2 100644 --- a/ThunksList.md +++ b/ThunksList.md @@ -90,8 +90,12 @@ ## api-ms-win-core-winrt-error-l1-1-0.dll | 函数 | Fallback | ---- | ----------- +| RoFailFastWithErrorContext | 什么也不做。 | RoOriginateError | 返回 TRUE. | RoOriginateErrorW | 返回 TRUE. +| RoOriginateLanguageException | 返回 TRUE. +| RoTransformError | 返回 TRUE. +| RoTransformErrorW | 返回 TRUE. ## api-ms-win-core-winrt-string-l1-1-0.dll | 函数 | Fallback @@ -624,6 +628,7 @@ | 函数 | Fallback | ---- | ----------- | CoGetApartmentType | 调用IComThreadingInfo。 +| RoGetAgileReference | 返回E_NOTIMPL ## pdh.dll | 函数 | Fallback diff --git a/src/Thunks/YY_Thunks.cpp b/src/Thunks/YY_Thunks.cpp index ceca80f..2624346 100644 --- a/src/Thunks/YY_Thunks.cpp +++ b/src/Thunks/YY_Thunks.cpp @@ -74,6 +74,7 @@ YY-Thunks支持的控制宏: _APPLY(api_ms_win_core_winrt_l1_1_0, "api-ms-win-core-winrt-l1-1-0" , 0 ) \ _APPLY(api_ms_win_core_winrt_string_l1_1_0, "api-ms-win-core-winrt-string-l1-1-0", 0 ) \ _APPLY(api_ms_win_core_winrt_error_l1_1_0, "api-ms-win-core-winrt-error-l1-1-0" , 0 ) \ + _APPLY(api_ms_win_core_winrt_error_l1_1_1, "api-ms-win-core-winrt-error-l1-1-1" , 0 ) \ _APPLY(api_ms_win_core_path_l1_1_0, "api-ms-win-core-path-l1-1-0" , 0 ) \ _APPLY(api_ms_win_core_synch_l1_2_0, "api-ms-win-core-synch-l1-2-0" , 0 ) diff --git a/src/Thunks/api-ms-win-core-com.hpp b/src/Thunks/api-ms-win-core-com.hpp index 83c851b..938589b 100644 --- a/src/Thunks/api-ms-win-core-com.hpp +++ b/src/Thunks/api-ms-win-core-com.hpp @@ -1,4 +1,4 @@ -#if (YY_Thunks_Target < __WindowsNT6_1) +#if (YY_Thunks_Target < __WindowsNT6_3) #include #endif @@ -74,4 +74,34 @@ namespace YY::Thunks return S_OK; } #endif + + +#if (YY_Thunks_Target < __WindowsNT6_3) + // Windows 8.1 [desktop apps | UWP apps] + // Windows Server 2012 R2 [desktop apps | UWP apps] + __DEFINE_THUNK( + ole32, + 16, + HRESULT, + WINAPI, + RoGetAgileReference, + _In_ enum AgileReferenceOptions options, + _In_ REFIID riid, + _In_ IUnknown* pUnk, + _COM_Outptr_ IAgileReference** ppAgileReference + ) + { + if (auto _pfnRoGetAgileReference = try_get_RoGetAgileReference()) + { + return _pfnRoGetAgileReference(options, riid, pUnk, ppAgileReference); + } + + if (pUnk == nullptr || ppAgileReference == nullptr) + return E_INVALIDARG; + + *ppAgileReference = nullptr; + + return E_NOTIMPL; + } +#endif } diff --git a/src/Thunks/api-ms-win-core-winrt-error.hpp b/src/Thunks/api-ms-win-core-winrt-error.hpp index f9b5c68..53f9e8d 100644 --- a/src/Thunks/api-ms-win-core-winrt-error.hpp +++ b/src/Thunks/api-ms-win-core-winrt-error.hpp @@ -1,9 +1,31 @@ -#if (YY_Thunks_Target < __WindowsNT6_2) +#if (YY_Thunks_Target < __WindowsNT6_3) #include +#include #endif namespace YY::Thunks { + +#if (YY_Thunks_Target < __WindowsNT6_2) + //Windows 8 [desktop apps | UWP apps] + //Windows Server 2012 [desktop apps | UWP apps] + __DEFINE_THUNK( + api_ms_win_core_winrt_error_l1_1_0, + 4, + void, + WINAPI, + RoFailFastWithErrorContext, + HRESULT hrError + ) + { + if (auto pRoFailFastWithErrorContext = try_get_RoFailFastWithErrorContext()) + { + pRoFailFastWithErrorContext(hrError); + } + } +#endif + + #if (YY_Thunks_Target < __WindowsNT6_2) //Windows 8 [desktop apps | UWP apps] @@ -58,4 +80,80 @@ namespace YY::Thunks return TRUE; } #endif + +#if (YY_Thunks_Target < __WindowsNT6_3) + //Windows 8.1 [desktop apps | UWP apps] + //Windows Server 2012 [desktop apps | UWP apps] + __DEFINE_THUNK( + api_ms_win_core_winrt_error_l1_1_1, + 12, + BOOL, + WINAPI, + RoOriginateLanguageException, + _In_ HRESULT error, + _In_opt_ HSTRING message, + _In_opt_ IUnknown* languageException + ) + { + if (auto pRoOriginateLanguageException = try_get_RoOriginateLanguageException()) + { + return pRoOriginateLanguageException(error, message, languageException); + } + if ((error == S_OK) || (!languageException) || WindowsIsStringEmpty(message)) + return FALSE; + // The RoOriginateLanguageException function behaves like RoOriginateError but takes another parameter that stores extra information about the error. + return TRUE; + } +#endif + +#if (YY_Thunks_Target < __WindowsNT6_2) + //Windows 8 [desktop apps | UWP apps] + //Windows Server 2012 [desktop apps | UWP apps] + __DEFINE_THUNK( + api_ms_win_core_winrt_error_l1_1_0, + 12, + BOOL, + WINAPI, + RoTransformError, + _In_ HRESULT oldError, + _In_ HRESULT newError, + _In_opt_ HSTRING message + ) + { + if (auto pRoTransformError = try_get_RoTransformError()) + { + return pRoTransformError(oldError, newError, message); + } + if ((oldError == S_OK && newError == S_OK) || WindowsIsStringEmpty(message)) + return FALSE; + return TRUE; + } +#endif + +#if (YY_Thunks_Target < __WindowsNT6_2) + //Windows 8 [desktop apps | UWP apps] + //Windows Server 2012 [desktop apps | UWP apps] + __DEFINE_THUNK( + api_ms_win_core_winrt_error_l1_1_0, + 16, + BOOL, + WINAPI, + RoTransformErrorW, + _In_ HRESULT oldError, + _In_ HRESULT newError, + _In_ UINT cchMax, + _When_(cchMax == 0, _In_reads_or_z_opt_(MAX_ERROR_MESSAGE_CHARS)) + _When_(cchMax > 0 && cchMax < MAX_ERROR_MESSAGE_CHARS, _In_reads_or_z_(cchMax) ) + _When_(cchMax >= MAX_ERROR_MESSAGE_CHARS, _In_reads_or_z_(MAX_ERROR_MESSAGE_CHARS) ) PCWSTR message + ) + { + if (auto pRoTransformErrorW = try_get_RoTransformErrorW()) + { + return pRoTransformErrorW(oldError, newError, cchMax, message); + } + if ((oldError == S_OK && newError == S_OK) || ((!cchMax) || !(message))) + return FALSE; + return TRUE; + } +#endif }