Again, a piece of information learnt the hard way. GetUniqueDeviceId, while the MSDN documentation guarantees a unique device ID in each device, doesn’t quite work the way it’s supposed to in actual practice. I don’t know exactly why that is, and there’s not much documentation, but the symptom is that multiple devices will keep throwing the same Device ID and thus its uniqueness is not guaranteed.
There are various workarounds you can use. In case your app just needs a different identifier for each device, the simplest and most elegant method is to generate a GUID and store it. Naturally, the side-effect of this is that if your app is ever uninstalled, the GUID is lost and the device gets a new identifier.
In such a case, where you need the device to be identified as the same device without storing any state locally, you may use a fixed seed and CryptProtectData it to generate the ID. CryptProtectData uses a provisioned private key on the device to encrypt a given string. This way, regardless of the state of your app, so long as you give it an identical string as input multiple times, you will get the exact same device identifier on the device, and yet a different identifier on different devices.
You can always go one step further to guarantee uniqueness and consistency even more. That would be to get the device’s IMEI number (if the device has a phone in it), and use CryptProtectData on that.
have you tried on HTC device with WM6 ?
Comment by javisantana — December 29, 2009 @ 12:59 am
Not really. The OEM needs to implement this function in their ROM, which most devices don’t seem to have.
I’ve tried on multiple HTC devices – both 5 and 6, and it doesn’t work on many of them. It may work on one or two specific models, though.
If you are sure your app will be installed on only one specific type of device, you could check it. Even checking it is an expensive affair since you need at least two, if not more, devices.
Comment by archisgore — December 29, 2009 @ 7:55 am