|
我想读取各种存储卡的serial number,代码如下:
----------------------------------------------------------------
#include "stdafx.h"
#include "windows.h"
#include "winioctl.h"
// retrieve the properties of a storage device or adapter.
typedef struct _STORAGE_DEVICE_DESCRIPTOR { ULONG Version; ULONG Size; UCHAR DeviceType; UCHAR DeviceTypeModifier; BOOLEAN RemovableMedia;
BOOLEAN CommandQueueing; ULONG VendorIdOffset; ULONG ProductIdOffset; ULONG ProductRevisionOffset; ULONG SerialNumberOffset; STORAGE_BUS_TYPE BusType;
ULONG RawPropertiesLength; UCHAR RawDeviceProperties[1];} STORAGE_DEVICE_DESCRIPTOR, *PSTORAGE_DEVICE_DESCRIPTOR;
typedef enum _STORAGE_QUERY_TYPE {
PropertyStandardQuery = 0,
PropertyExistsQuery,
PropertyMaskQuery,
PropertyQueryMaxDefined
} STORAGE_QUERY_TYPE, *PSTORAGE_QUERY_TYPE;
// retrieve the properties of a storage device or adapter.
typedef enum _STORAGE_PROPERTY_ID {
StorageDeviceProperty = 0,
StorageAdapterProperty,
StorageDeviceIdProperty
} STORAGE_PROPERTY_ID, *PSTORAGE_PROPERTY_ID;
// retrieve the properties of a storage device or adapter.
typedef struct _STORAGE_PROPERTY_QUERY {
STORAGE_PROPERTY_ID PropertyId;
STORAGE_QUERY_TYPE QueryType;
UCHAR AdditionalParameters[1];
} STORAGE_PROPERTY_QUERY, *PSTORAGE_PROPERTY_QUERY;
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hnd;
STORAGE_PROPERTY_QUERY Query;
PSTORAGE_DEVICE_DESCRIPTOR pDevDesc;
DWORD dwOutBytes;
char tzCFCardID[20];
hnd = CreateFile("\\\\.\\g:", GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
Query.PropertyId = StorageDeviceProperty;
Query.QueryType = PropertyStandardQuery;
pDevDesc=(STORAGE_DEVICE_DESCRIPTOR *)LocalAlloc(LMEM_ZEROINIT,3000);
if(!DeviceIoControl(hnd, CTL_CODE(IOCTL_STORAGE_BASE, 0x0500, METHOD_BUFFERED, FILE_ANY_ACCESS), // info of device property
&Query, sizeof(STORAGE_PROPERTY_QUERY), // input data buffer
(LPVOID)pDevDesc, pDevDesc->Size, // output data buffer
&dwOutBytes, // out's length
(LPOVERLAPPED)NULL))
{
sprintf(tzCFCardID, "ERRORID:%lu", GetLastError());
printf("%s\n",tzCFCardID);
}
printf("serial number offset:%lu\n",pDevDesc->SerialNumberOffset);
LocalFree(pDevDesc);
CloseHandle(hnd);
return 0;
}
----------------------------------------------------------------
但是pDevDesc->SerialNumberOffset的值总是0,能帮下我吗?
谢谢!
|
|