幾個有用的Windows Mobile相關方法

來源:互聯網
上載者:User

1 取得裝置ID
#include
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
CString strNextChar;
strNextChar.Format(TEXT("%02X"), arrOutBuff);
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);
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.