几个有用的Windows Mobile相关方法

1  取得设备ID。
 
#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("");
 }
}
 
说明:Windows Mobile 5.0已经添加了专门的API完成此任务,对于2003以下的设备可以用此方法。此方法是否能取道ID还取决与硬件制造商是否已经实现了改方法。因为smartphone具备2-Tie安全性,所以此方法如果没有授权证书可能会调用失败。
 
2  取得设备信息
TCHAR wszMachineName[128];
 SystemParametersInfo(SPI_GETOEMINFO, sizeof(wszMachineName),
             &wszMachineName, 0);
取得设备OEM信息。
TCHAR wszVersion[256];
 SystemParametersInfo(SPI_GETPLATFORMTYPE, sizeof(wszVersion),
             &wszVersion, 0);
取得平台信息。
 
3  创建GUID
CString CreateGUID()
{
 TCHAR wGuid[37];
 SYSTEMTIME systime;
 FILETIME filetime;
  // construct GUID
 GetSystemTime(&systime);
 SystemTimeToFileTime(&systime,&filetime);
 DWORD tick=GetTickCount();
 DWORD highWord=filetime.dwHighDateTime+0x146BF4;
  // convert GUID to a string
 wsprintf(wGuid,TEXT("%08.8x-%04.4x-%04.4x-%04.4x-%04.4x%04.4x%04.4x"),
  filetime.dwLowDateTime,
  LOWORD(highWord),
  HIWORD(highWord |0x10000000),
  LOWORD(rand()),
  HIWORD(tick),
  LOWORD(tick),
  LOWORD(rand()));
 return CString(wGuid);
}

你可能感兴趣的:(windows,职场,mobile,休闲)