Repository navigation
Add IsPackagedProcess and IsSelfContained to common insights PartB fields #6233
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
Changes from all commits
4314c63
ee8ce4e
e87783b
f09c6e5
1a4bb00
331c905
2566480
41ebce0
bf1ad01
88833e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Copyright (c) Microsoft Corporation and Contributors. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #ifndef __APPMODEL_IDENTITY_ISPACKAGEDPROCESS_H | ||
| #define __APPMODEL_IDENTITY_ISPACKAGEDPROCESS_H | ||
|
|
||
| #include <appmodel.h> | ||
|
|
||
| namespace AppModel::Identity | ||
| { | ||
| inline HRESULT IsPackagedProcess_nothrow(bool& isPackagedProcess) noexcept | ||
| { | ||
| isPackagedProcess = false; | ||
| UINT32 n{}; | ||
|
agniuks marked this conversation as resolved.
Resolved
|
||
| const auto rc{ ::GetCurrentPackageFullName(&n, nullptr) }; | ||
| RETURN_HR_IF(HRESULT_FROM_WIN32(rc), (rc != APPMODEL_ERROR_NO_PACKAGE) && (rc != ERROR_INSUFFICIENT_BUFFER)); | ||
| isPackagedProcess = (rc == ERROR_INSUFFICIENT_BUFFER); | ||
| return S_OK; | ||
| } | ||
|
|
||
| inline bool IsPackagedProcess() | ||
| { | ||
| UINT32 n{}; | ||
| const auto rc{ ::GetCurrentPackageFullName(&n, nullptr) }; | ||
| THROW_HR_IF_MSG(HRESULT_FROM_WIN32(rc), (rc != APPMODEL_ERROR_NO_PACKAGE) && (rc != ERROR_INSUFFICIENT_BUFFER), "GetCurrentPackageFullName rc=%d", rc); | ||
| return rc == ERROR_INSUFFICIENT_BUFFER; | ||
| } | ||
| } | ||
|
|
||
| #endif // __APPMODEL_IDENTITY_ISPACKAGEDPROCESS_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,23 @@ inline bool IsSelfContained() | |
| THROW_IF_FAILED(WindowsAppRuntime_IsSelfContained(&isSelfContained)); | ||
| return !!isSelfContained; | ||
| } | ||
|
|
||
| /// Non-throwing variant using dynamic loading (safe before DLL is loaded). | ||
| inline HRESULT IsSelfContained_nothrow(bool& isSelfContained) noexcept | ||
| { | ||
| isSelfContained = false; | ||
| auto module = ::GetModuleHandleW(L"Microsoft.WindowsAppRuntime.dll"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Silently swallows errors. if WIL is your friend :-)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. !module is the normal case when the DLL isn't loaded yet (like during bootstrap). If we RETURN_LAST_ERROR_IF_NULL here it'd bubble up as a real error. Would something like LOG_LAST_ERROR_IF_NULL + still returning S_OK be a good middle ground?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahhh, but in this case it is an error. It's the caller's decision if that's a problem for them, or if they want to ignore it as 'expected' If this is called before the DLL is loaded (e.g. bootstrap) then would the caller hit this again later and get a different answer? Given the TraceLogging callsite calls this on 1st use and caches the result the question is, does that 1st call happen after bootstrapping? If not how would that cached answer be revised - or would it always be wrong 'cause too early?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the logic still works out: self-contained apps already have the DLL loaded (no |
||
| RETURN_LAST_ERROR_IF_NULL(module); | ||
| using IsSelfContainedFn = HRESULT(__stdcall*)(BOOL*); | ||
| auto fn = reinterpret_cast<IsSelfContainedFn>( | ||
| ::GetProcAddress(module, "WindowsAppRuntime_IsSelfContained")); | ||
| RETURN_LAST_ERROR_IF_NULL(fn); | ||
| BOOL result{}; | ||
| const auto hr{ fn(&result) }; | ||
| RETURN_IF_FAILED(hr); | ||
| isSelfContained = !!result; | ||
| return S_OK; | ||
| } | ||
| } | ||
| #endif // defined(__cplusplus) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.