WinCE中如何获取PDA的ID码
在PALM中﹐每台PDA都有唯一的ID碼﹐我想在WINCE中也應該有類似的ID碼﹐但如何在程序中獲取該ID碼﹖
答案就是PPC没有统一的Device ID
如果你为ipaq开发程序,那么两种方法可以取得device id:
1 Download Compaq iPAQ SDK 然后用 CPQInfoGetSerialNo function (定义在CPQInfo.h中)取得.
2 如果你只想用通用SDK,那么有一个取巧的办法,就是运行\windows\CreateAssetFile.exe ,然后读取自动生成的\windows\cpqAssetData.dat 文件, DeviceID就在里面, 这里有一段程序专门干这事:
1 CString GetSerialNumber()
2
3 {
4
5 // Start CreateAssetFile.exe
6
7 PROCESS_INFORMATION pi;
8
9 if (!::CreateProcess(TEXT("\windows\CreateAssetFile.exe"),
10
11 NULL, NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi))
12
13 {
14
15 m_strCompaqIpaqId = _T("");
16
17 m_strErrorMessage += _T("Cannot run \windows\CreateAssetFile.exe file.");
18
19 return TEXT("");
20
21 }
22
23
24
25 // Wait until CreateAssetFile.exe will be finished
26
27 ::WaitForSingleObject(pi.hProcess, INFINITE);
28
29
30
31 // Read data from cpqAssetData.dat file
32
33 HANDLE hInFile;
34
35 TCHAR strSN[65];
36
37 DWORD dwBytesRead;
38
39 hInFile = CreateFile(TEXT("\windows\cpqAssetData.dat"), GENERIC_READ,
40
41 FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
42
43
44
45 if (hInFile == INVALID_HANDLE_VALUE) {
46
47 m_strCompaqIpaqId = _T("");
48
49 m_strErrorMessage += _T("Cannot read \windows\cpqAssetData.dat file.");
50
51 return TEXT("");
52
53 }
54
55
56
57 SetFilePointer(hInFile, 976, NULL, FILE_BEGIN);
58
59 memset(strSN, 0, 64 * sizeof(TCHAR));
60
61 ReadFile(hInFile, &strSN, 64, &dwBytesRead, NULL);
62
63 CloseHandle(hInFile);
64
65
66
67 return CString(strSN);
68
69 }
70
2
3 {
4
5 // Start CreateAssetFile.exe
6
7 PROCESS_INFORMATION pi;
8
9 if (!::CreateProcess(TEXT("\windows\CreateAssetFile.exe"),
10
11 NULL, NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi))
12
13 {
14
15 m_strCompaqIpaqId = _T("");
16
17 m_strErrorMessage += _T("Cannot run \windows\CreateAssetFile.exe file.");
18
19 return TEXT("");
20
21 }
22
23
24
25 // Wait until CreateAssetFile.exe will be finished
26
27 ::WaitForSingleObject(pi.hProcess, INFINITE);
28
29
30
31 // Read data from cpqAssetData.dat file
32
33 HANDLE hInFile;
34
35 TCHAR strSN[65];
36
37 DWORD dwBytesRead;
38
39 hInFile = CreateFile(TEXT("\windows\cpqAssetData.dat"), GENERIC_READ,
40
41 FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
42
43
44
45 if (hInFile == INVALID_HANDLE_VALUE) {
46
47 m_strCompaqIpaqId = _T("");
48
49 m_strErrorMessage += _T("Cannot read \windows\cpqAssetData.dat file.");
50
51 return TEXT("");
52
53 }
54
55
56
57 SetFilePointer(hInFile, 976, NULL, FILE_BEGIN);
58
59 memset(strSN, 0, 64 * sizeof(TCHAR));
60
61 ReadFile(hInFile, &strSN, 64, &dwBytesRead, NULL);
62
63 CloseHandle(hInFile);
64
65
66
67 return CString(strSN);
68
69 }
70
我最擅长从零开始创造世界,所以从来不怕失败,它最多也就让我一无所有。