Problem with GetDeviceUniqueID on Windows Mobile 6

I use code very similar to the following question: Unable to find entry point "GetDeviceUniqueID" in DLL "coredll.dll" PInvoke

(My code inserted here for posterity):

[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; } 

I have no problem compiling the program on my emulator and deploying it to my physical device. However, this code always returns the value: "00000000-0000-0000-0000-00000000000000000000" .

(For introspection, i_rc has a value of 2147024809 ).

What is going wrong? Why does the function return the default / safe value?

+5
source share
1 answer

It turns out that the app_data variable should be at least 8 characters long .

(As prescribed - http://www.devlper.com/2008/10/getting-unique-device-id-using-getdeviceuniqueid-api/ )

Madness, since this rather important set of requirements, seems to be not documented anywhere.

Bonus We give other requirements here if we lose the specified site in the sands of time:

 HRESULT GetDeviceUniqueID(LPBYTE pbApplicationData, DWORD cbApplictionData, DWORD dwDeviceIDVersion, LPBYTE pbDeviceIDOutput, DWORD *pcbDeviceIDOutput); 
  • pbApplicationData - Must be 8 characters long, otherwise the API will fail
  • dwDeviceIDVersion - must be 1
  • pbDeviceIDOutput - out parameter that will be populated with a unique device identifier
  • pcbDeviceIDOutput - length of pbDeviceIDOutput
+5
source

Source: https://habr.com/ru/post/1200132/


All Articles