【发布时间】:2020-09-18 01:02:15
【问题描述】:
在线文档与 C++/WinRT 的“基本事实”之间似乎存在巨大的脱节。到目前为止,这是我认为我已经弄清楚的:
#include <winrt/Windows.System.Profile.h>
using namespace winrt;
using namespace winrt::Windows;
// ...
auto userBuf = System::Profile::SystemIdentification::GetSystemIdForPublisher().Id();
hstring userStr; // = ? How to get this from userBuf?
auto user = System::User::GetFromId (userStr);
hstring firstName = user.GetPropertyAsync (System::KnownUserProperties::FirstName());
hstring lastName = user.GetPropertyAsync (System::KnownUserProperties::LastName());
是否有更简单/更好的途径来获取当前用户的属性? 如何从 GetSystemIdForPublisher().Id() 返回的缓冲区中获取 User::GetFromId(_) 所需的 hstring?
我发现我可以从 userBuf.data() 获得一个 uint8_t*,但 userBuf.Length() 是链接器中未解析的外部符号。
另外,我的理解是否正确
System::Profile::SystemIdentification::GetSystemIdForUser(nullptr).Id();
会得到当前用户的ID吗? (假设授予 userSystemId 能力)
【问题讨论】:
-
如果无法访问
IBuffer的Length()属性,则可能是#include <winrt/Windows.Storage.Streams.h>头文件失败。 -
谢谢。那确实解决了。
间接包含 #include "winrt/impl/Windows.Storage.Streams.0.h",它声明了模板 struct consume_Windows_Storage_Streams_IBuffer { } 带有 Length() 和 data() 函数。我的搜索只把我带到了那里。 data() 是内联的;长度()不是。这些东西的文档真的很不充分。这一切似乎都很神秘。 -
GetSystemIdForUser 不返回用户 ID。它返回系统的 id..
-
是的,我明白了。我只是有点惊讶,不知何故无法从中获取用户 ID。函数文档暗示存在“当前用户”的一些概念,但无法获取该用户的用户 ID。但是,根据本主题底部的回复,这一切现在都没有实际意义。我已经放弃了 UWP 上下文中“当前用户”的概念。