News | Articles | Libraries | Developer Tools | Books | Forum Links | Search   
Sections:
 

QA: How can I get a serial number of a Pocket PC 2002 device?

By Vassili Philippov, December 27, 2001.
Print version

Question

As far as I know all Pocket PC 2002 devices support built-in serial numbers. How can I read it?

Answer

Even in Pocket PC 2000 it was recommended for OEM vendors to implement a built-in serial number and provide access using KernelIoControl function. But no OEM vendor did it.

As I understand now (in Pocket PC 2002) Microsoft forced OEM vendors to implement a built-in serial number with access by KernelIoControl. All Pocket PC 2002 devices I tested support this method.

Source code

Here is a sample code that returns a serial number as a string:

#include <WINIOCTL.H> extern "C" __declspec(dllimport) BOOL KernelIoControl( DWORD dwIoControlCode, LPVOID lpInBuf, DWORD nInBufSize, LPVOID lpOutBuf, DWORD nOutBufSize, LPDWORD lpBytesReturned ); #define IOCTL_HAL_GET_DEVICEID CTL_CODE(FILE_DEVICE_HAL, 21, METHOD_BUFFERED, FILE_ANY_ACCESS) CString GetSerialNumberFromKernelIoControl() { DWORD dwOutBytes; const int nBuffSize = 4096; byte arrOutBuff[nBuffSize]; BOOL bRes = ::KernelIoControl(IOCTL_HAL_GET_DEVICEID, 0, 0, arrOutBuff, nBuffSize, &dwOutBytes); if (bRes) { CString strDeviceInfo; for (unsigned int i = 0; i<dwOutBytes; i++) { CString strNextChar; strNextChar.Format(TEXT("%02X"), arrOutBuff[i]); strDeviceInfo += strNextChar; } CString strDeviceId = strDeviceInfo.Mid(40,2) + strDeviceInfo.Mid(45,9) + strDeviceInfo.Mid(70,6); return strDeviceId; } else { return _T(""); } }

Note: this serial number is not equal to serial number written on the device. It is because I did not know how to format the bits extracted from the buffer. So you can consider this string as a string that is unique for each Pocket PC device.

Related resources:

Discuss

Discuss this article. Here you can write your comments and read comments of other developers.
Rate this article:     Poor Excellent    
 12345 
© 2001-2005 Pocket PC Developer Network, a division of Spb Software House