【问题标题】:getting the Unique DeviceId in Windows Phone 8.1 using C++ code使用 C++ 代码在 Windows Phone 8.1 中获取唯一的 DeviceId
【发布时间】:2015-02-27 10:26:20
【问题描述】:

我正在尝试使用 c++ 代码获取 windows phone 8.1 的唯一 44 位设备 ID。我已经按照以下链接进行操作。

http://abundantcode.com/alternate-way-of-getting-the-unique-deviceid-in-windows-phone-8/#comment-85511

只有一行的短代码,

var UniqueID = Windows.Phone.System.Analytics.HostInformation.PublisherHostId;

但我遇到了很多错误。

error C3083: 'Analytics': the symbol to the left of a '::' must be a type , 
error C3083: 'HostInformation': the symbol to the left of a '::'must be a `type  ,`
error C2039: 'PublisherHostId' : is not a member of'Windows::Phone::System'  ,  
error C2065: 'PublisherHostId' : undeclared identifier

我还定义了ID_CAP_IDENTIY_DEVICE属性,这里就是这样提到的。

<Capability Name="ID_CAP_IDENTITY_DEVICE"/>

虽然我很困惑这是对还是错。

【问题讨论】:

  • 您确定要构建 Windows Phone 8.0 C++?这对我来说编译得很好:auto x = Windows::Phone::System::Analytics::HostInformation::PublisherHostId;
  • 对不起!它是 Windows Phone 8.1,是的,我正在用 C++ 做。
  • 好的,请更新标题和标签然后:-)

标签: c++ windows-phone-8.1 uniqueidentifier win-universal-app


【解决方案1】:

对于 Windows Phone 8.0,您可以使用 PublisherHostId,但对于 Windows Phone 8.1 本机代码项目,您需要使用 HardwareIdentification::GetPackageSpecificToken() aka ASHWID

这样您就可以更轻松地与 Windows 8.1 共享代码。对于给定设备上的给定应用,此 ID 是恒定的,但会因应用和设备而异。

这是一个适用于 Windows Phone 8.1 的示例:

using namespace Windows::System::Profile;
using namespace Windows::Security::Cryptography;
using namespace Platform;

auto token = HardwareIdentification::GetPackageSpecificToken(nullptr);
Array<byte>^ buffer = ref new Array<byte>(token->Id->Length);

// Nothing to do with crypto; just a helpful class 
// to convert IBuffer^ -> Array^
CryptographicBuffer::CopyToByteArray(token->Id, &buffer);

// Output the first four bytes of the key
char key[9];
sprintf_s(key, sizeof(key) / sizeof(key[0]), "%02X%02X%02X%02X", 
  buffer[0], buffer[1], buffer[2], buffer[3]);
OutputDebugStringA(key);

【讨论】:

  • 谢谢@Peter,我要试试。
  • 我使用了HardwareToken^ packageSpecificToken; packageSpecificToken = Windows::System::Profile::HardwareIdentification::GetPackageSpecificToken(nonce);,但它给了我HardwareTokennonce的未定义标识符错误。
  • 添加了 null nonce 的示例
  • 它工作得很好,但我想知道它的大小是 31 而不是 44,都是一样的吗?
  • 不,它们不一样。一个是按发布者共享的,另一个是按应用共享的
猜你喜欢
  • 1970-01-01
  • 2015-11-15
  • 1970-01-01
  • 1970-01-01
  • 2014-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多