wince SD卡读取ID有问题
wince SD卡读取ID有问题
#include <windows.h>
#include "winioctl.h"
#include "storemgr.h"
#define IOCTL_DISK_GET_STORAGEID CTL_CODE(FILE_DEVICE_DISK,0x709,METHOD_BUFFERED,FILE_ANY_ACCESS)
typedef struct _STORAGE_IDENTIFICATION
{
DWORD dwSize;
DWORD dwFlags;
DWORD dwManufactureIDOffset;
DWORD dwSerialNumOffset;
} STORAGE_IDENTIFICATION, *PSTORAGE_IDENTIFICATION;
inline bool GetStroageID(LPCTSTR szDisk, BYTE *SerialNo)
{
HANDLE hDisk = CreateFile(szDisk, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if(!hDisk || hDisk ==INVALID_HANDLE_VALUE)
{
Com_PrintLog(LOG_TYPE_ERROR, LOG_MODULE_HMI, "[main][GetStroageID][CreateFile-->Fail]");
return false;
}
PSTORAGE_IDENTIFICATION pStoreInfo = (PSTORAGE_IDENTIFICATION) new BYTE[3000];
DWORD dwBytesRet = 0;
if (!DeviceIoControl(hDisk, IOCTL_DISK_GET_STORAGEID, NULL, 0, pStoreInfo, 3000, &dwBytesRet, NULL))
{
Com_PrintLog(LOG_TYPE_ERROR, LOG_MODULE_HMI, "[main][GetStroageID][DeviceIoControl fail]");
if(pStoreInfo)
{
delete [] pStoreInfo;
pStoreInfo = NULL;
}
CloseHandle(hDisk);
return false;
}
if(dwBytesRet == 0)
{
Com_PrintLog(LOG_TYPE_ERROR, LOG_MODULE_HMI, "[main][GetStroageID][dwBytesRet=0]");
if(pStoreInfo)
{
delete [] pStoreInfo;
pStoreInfo = NULL;
}
CloseHandle(hDisk);
return false;
}
BYTE *ManuID = (((BYTE *)pStoreInfo) + pStoreInfo->dwManufactureIDOffset);
BYTE *tempSerialNo = (((BYTE *)pStoreInfo) + pStoreInfo->dwSerialNumOffset);
Com_PrintLog(LOG_TYPE_ERROR, LOG_MODULE_HMI, "[main][GetStroageID][strcpy][tempSerialNo=%X,tempSerialNo_d=%d]",tempSerialNo,tempSerialNo);
strcpy((char *)SerialNo, (const char *)tempSerialNo);
Com_PrintLog(LOG_TYPE_ERROR, LOG_MODULE_HMI, "[main][GetStroageID][strcpy][SerialNo=%X]",SerialNo);
if(pStoreInfo)
{
delete [] pStoreInfo;
pStoreInfo = NULL;
}
CloseHandle(hDisk);
Com_PrintLog(LOG_TYPE_ERROR, LOG_MODULE_HMI, "[main][GetStroageID][return true]");
return true;
}
用查看工具在xp系统下看到 ID是 52583B32,但是打印出来的是
tempSerialNo=%X,tempSerialNo_d
tempSerialNo=22B72,tempSerialNo_d=142194
这数值对不上,是不是打印输出不对
[解决办法]
明显是你的 CE 下获取到的 ID 有问题。
试试偶在 CSDN 博客的代码:
http://blog.csdn.net/91program/article/details/6612675