Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

roapi一些错误处理函数 #142

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ThunksList.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -624,6 +628,7 @@
| 函数 | Fallback
| ---- | -----------
| CoGetApartmentType | 调用IComThreadingInfo。
| RoGetAgileReference | 返回E_NOTIMPL

## pdh.dll
| 函数 | Fallback
Expand Down
1 change: 1 addition & 0 deletions src/Thunks/YY_Thunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

Expand Down
32 changes: 31 additions & 1 deletion src/Thunks/api-ms-win-core-com.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if (YY_Thunks_Target < __WindowsNT6_1)
#if (YY_Thunks_Target < __WindowsNT6_3)
#include <combaseapi.h>
#endif

Expand Down Expand Up @@ -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
}
100 changes: 99 additions & 1 deletion src/Thunks/api-ms-win-core-winrt-error.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
#if (YY_Thunks_Target < __WindowsNT6_2)
#if (YY_Thunks_Target < __WindowsNT6_3)
#include <roerrorapi.h>
#include <winstring.h>
#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);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果从API语义上,RoFailFastWithErrorContext调用后不应该继续执行……

能解释一下原因吗?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没太懂,RoFailFastWithErrorContext不是这次你新增的吗?还是说抓个函数你有其他的参考来源?

Copy link
Contributor Author

@HIllya51 HIllya51 Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不好意思,眼花了。我记得好像参考了哪个来着,奇怪

#endif


#if (YY_Thunks_Target < __WindowsNT6_2)

//Windows 8 [desktop apps | UWP apps]
Expand Down Expand Up @@ -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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fallback逻辑为什么不调用RoOriginateError?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

他们都是win8的api,fallback也没用吧...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

他们都是win8的api,fallback也没用吧...

你的注释写着 RoOriginateLanguageException 8.1引入

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确实

}
#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
}
Loading