【问题标题】:Trouble implementing GetDeviceUniqueID on Windows Mobile 6在 Windows Mobile 6 上实现 GetDeviceUniqueID 时遇到问题
【发布时间】:2014-10-05 21:11:44
【问题描述】:

我使用的代码与以下 Stack Overflow 问题非常相似: Can't find an Entry Point 'GetDeviceUniqueID' in a PInvoke DLL 'coredll.dll'

(为了后代,我的代码粘贴在这里):

[DllImport("coredll.dll")]
private extern static int GetDeviceUniqueID([In, Out] byte[] appdata,
                                            int cbApplictionData,
                                            int dwDeviceIDVersion,
                                            [In, Out] byte[] deviceIDOuput,
                                            out uint pcbDeviceIDOutput);



public static string GetDeviceID()
{
    string appString = "MyApp";
    byte[] appData = new byte[appString.Length];
    for (int count = 0; count < appString.Length; count++)
    {
        appData[count] = (byte)appString[count];
    }

    int appDataSize = appData.Length;
    byte[] DeviceOutput = new byte[20];
    uint SizeOut = 20;
    int i_rc = GetDeviceUniqueID(appData, appDataSize, 1, DeviceOutput, out SizeOut);

    string idString = "";
    for (int i = 0; i < DeviceOutput.Length; i++)
    {
        if (i == 4 || i == 6 || i == 8 || i == 10)
            idString = String.Format("{0}-{1}", idString, DeviceOutput[i].ToString("x2"));
        else
            idString = String.Format("{0}{1}", idString, DeviceOutput[i].ToString("x2"));
    }
    return idString;


}

在我的模拟器上编译程序并部署到我的物理设备上没有问题。但是,此代码始终返回值:"00000000-0000-0000-0000-00000000000000000000"

(自省后,i_rc 的值为 2147024809)。

出了什么问题?为什么函数似乎返回默认/安全值?

【问题讨论】:

    标签: c# .net-3.5 windows-mobile


    【解决方案1】:

    原来 app_data 变量应该至少有 8 个字符长

    (由-web.archive.org规定)

    令人抓狂,因为这组相当重要的要求似乎没有记录在任何地方。

    奖励 - 我将在此处列出其他要求,以防我们将上述网站丢给时间之沙:

    HRESULT GetDeviceUniqueID(LPBYTE pbApplicationData, DWORD cbApplictionData,
                              DWORD dwDeviceIDVersion, LPBYTE pbDeviceIDOutput,
                              DWORD *pcbDeviceIDOutput);
    
    • pbApplicationData - 长度必须为 8 个字符,否则 API 将失败
    • dwDeviceIDVersion - 应该是 1
    • pbDeviceIDOutput - 一个输出参数,将填充设备特定的唯一 ID
    • pcbDeviceIDOutput - pbDeviceIDOutput 的长度

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-31
      • 2023-04-09
      • 1970-01-01
      • 2015-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-01
      相关资源
      最近更新 更多