WinCE獲取SD卡序列號(hào)
{
BOOL bRes = FALSE;
PSTORAGE_IDENTIFICATION pStoreInfo = NULL;
HANDLE hDisk = INVALID_HANDLE_VALUE;
__try
{
//The buffer for storing data
const DWORD BUFFER_SIZE = 300;
//Allocate the size for the struct
pStoreInfo = (PSTORAGE_IDENTIFICATION) new BYTE[BUFFER_SIZE];
if(pStoreInfo == NULL)
{
__leave;
}
//Open the driver
hDisk = CreateFile(strDiskName.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if(hDisk == INVALID_HANDLE_VALUE)
{
__leave;
}
//Get the ID from the driver
DWORD dwBytesRet = 0;
if (DeviceIoControl(hDisk, IOCTL_DISK_GET_STORAGEID, NULL, 0, pStoreInfo, BUFFER_SIZE, dwBytesRet, NULL) == FALSE)
{
__leave;
}
//Get the manufacture ID
if (pStoreInfo->dwManufactureIDOffset != 0)
{
char *pManufactureID = reinterpret_cast
if(pStoreInfo->dwSerialNumOffset != 0)
{
strManufactureID.assign(pManufactureID,pStoreInfo->dwSerialNumOffset - pStoreInfo->dwManufactureIDOffset);
}
else
{
strManufactureID = pManufactureID;
}
}
if(pStoreInfo->dwSerialNumOffset != 0)
{
char *pSerialNum = reinterpret_cast
strSerialNum = pSerialNum;
}
bRes = TRUE;
}
__finally
{
if(pStoreInfo != NULL)
{
delete []pStoreInfo;
}
if(hDisk != INVALID_HANDLE_VALUE)
{
CloseHandle(hDisk);
}
}
return bRes;
}
評(píng)論