关于获取硬盘信息的代码。 ( 积分: 50 )

  • 主题发起人 主题发起人 xf47
  • 开始时间 开始时间
X

xf47

Unregistered / Unconfirmed
GUEST, unregistred user!
请大家帮忙看一下我把C的代码转成DELPHI的时候那里有问题?<br>×××××这是我在网上查到的VC的代码××××××<br>// IOCTL控制码<br>#define IOCTL_STORAGE_QUERY_PROPERTY &nbsp; CTL_CODE(IOCTL_STORAGE_BASE, 0x0500, METHOD_BUFFERED, FILE_ANY_ACCESS)<br>// 存储设备的总线类型<br>typedef enum _STORAGE_BUS_TYPE {<br> &nbsp; &nbsp;BusTypeUnknown = 0x00,<br> &nbsp; &nbsp;BusTypeScsi,<br> &nbsp; &nbsp;BusTypeAtapi,<br> &nbsp; &nbsp;BusTypeAta,<br> &nbsp; &nbsp;BusType1394,<br> &nbsp; &nbsp;BusTypeSsa,<br> &nbsp; &nbsp;BusTypeFibre,<br> &nbsp; &nbsp;BusTypeUsb,<br> &nbsp; &nbsp;BusTypeRAID,<br> &nbsp; &nbsp;BusTypeMaxReserved = 0x7F<br>} STORAGE_BUS_TYPE, *PSTORAGE_BUS_TYPE;<br> &nbsp;<br>// 查询存储设备属性的类型<br>typedef enum _STORAGE_QUERY_TYPE {<br> &nbsp; &nbsp;PropertyStandardQuery = 0, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 读取描述<br> &nbsp; &nbsp;PropertyExistsQuery, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 测试是否支持<br> &nbsp; &nbsp;PropertyMaskQuery, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 读取指定的描述<br> &nbsp; &nbsp;PropertyQueryMaxDefined &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 验证数据<br>} STORAGE_QUERY_TYPE, *PSTORAGE_QUERY_TYPE;<br> &nbsp;<br>// 查询存储设备还是适配器属性<br>typedef enum _STORAGE_PROPERTY_ID {<br> &nbsp; &nbsp;StorageDeviceProperty = 0, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 查询设备属性<br> &nbsp; &nbsp;StorageAdapterProperty &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 查询适配器属性<br>} STORAGE_PROPERTY_ID, *PSTORAGE_PROPERTY_ID;<br> &nbsp;<br>// 查询属性输入的数据结构<br>typedef struct _STORAGE_PROPERTY_QUERY {<br> &nbsp; &nbsp;STORAGE_PROPERTY_ID PropertyId; &nbsp; &nbsp; // 设备/适配器<br> &nbsp; &nbsp;STORAGE_QUERY_TYPE QueryType; &nbsp; &nbsp; &nbsp; // 查询类型 <br> &nbsp; &nbsp;UCHAR AdditionalParameters[1]; &nbsp; &nbsp; &nbsp;// 额外的数据(仅定义了象征性的1个字节)<br>} STORAGE_PROPERTY_QUERY, *PSTORAGE_PROPERTY_QUERY;<br> &nbsp;<br>// 查询属性输出的数据结构<br>typedef struct _STORAGE_DEVICE_DESCRIPTOR {<br> &nbsp; &nbsp;ULONG Version; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 版本<br> &nbsp; &nbsp;ULONG Size; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 结构大小<br> &nbsp; &nbsp;UCHAR DeviceType; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 设备类型<br> &nbsp; &nbsp;UCHAR DeviceTypeModifier; &nbsp; &nbsp; &nbsp; &nbsp; // SCSI-2额外的设备类型<br> &nbsp; &nbsp;BOOLEAN RemovableMedia; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 是否可移动<br> &nbsp; &nbsp;BOOLEAN CommandQueueing; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 是否支持命令队列<br> &nbsp; &nbsp;ULONG VendorIdOffset; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 厂家设定值的偏移<br> &nbsp; &nbsp;ULONG ProductIdOffset; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 产品ID的偏移<br> &nbsp; &nbsp;ULONG ProductRevisionOffset; &nbsp; &nbsp; &nbsp;// 产品版本的偏移<br> &nbsp; &nbsp;ULONG SerialNumberOffset; &nbsp; &nbsp; &nbsp; &nbsp; // 序列号的偏移<br> &nbsp; &nbsp;STORAGE_BUS_TYPE BusType; &nbsp; &nbsp; &nbsp; &nbsp; // 总线类型<br> &nbsp; &nbsp;ULONG RawPropertiesLength; &nbsp; &nbsp; &nbsp; &nbsp;// 额外的属性数据长度<br> &nbsp; &nbsp;UCHAR RawDeviceProperties[1]; &nbsp; &nbsp; // 额外的属性数据(仅定义了象征性的1个字节)<br>} STORAGE_DEVICE_DESCRIPTOR, *PSTORAGE_DEVICE_DESCRIPTOR;<br> &nbsp;<br>// 取设备属性信息<br>// hDevice -- 设备句柄<br>// pDevDesc -- 输出的设备描述和属性信息缓冲区指针(包含连接在一起的两部分)<br>BOOL GetDriveProperty(HANDLE hDevice, PSTORAGE_DEVICE_DESCRIPTOR pDevDesc)<br>{<br> &nbsp; &nbsp;STORAGE_PROPERTY_QUERY Query; &nbsp; &nbsp;// 查询输入参数<br> &nbsp; &nbsp;DWORD dwOutBytes; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// IOCTL输出数据长度<br> &nbsp; &nbsp;BOOL bResult; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// IOCTL返回值<br> &nbsp;<br> &nbsp; &nbsp;// 指定查询方式<br> &nbsp; &nbsp;Query.PropertyId = StorageDeviceProperty;<br> &nbsp; &nbsp;Query.QueryType = PropertyStandardQuery;<br> &nbsp;<br> &nbsp; &nbsp;// 用IOCTL_STORAGE_QUERY_PROPERTY取设备属性信息<br> &nbsp; &nbsp;bResult = ::DeviceIoControl(hDevice, // 设备句柄<br> &nbsp; &nbsp; &nbsp; &nbsp;IOCTL_STORAGE_QUERY_PROPERTY, &nbsp; &nbsp;// 取设备属性信息<br> &nbsp; &nbsp; &nbsp; &nbsp;&amp;Query, sizeof(STORAGE_PROPERTY_QUERY), &nbsp; &nbsp;// 输入数据缓冲区<br> &nbsp; &nbsp; &nbsp; &nbsp;pDevDesc, pDevDesc-&gt;Size, &nbsp; &nbsp; &nbsp; &nbsp;// 输出数据缓冲区<br> &nbsp; &nbsp; &nbsp; &nbsp;&amp;dwOutBytes, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 输出数据长度<br> &nbsp; &nbsp; &nbsp; &nbsp;(LPOVERLAPPED)NULL); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 用同步I/O &nbsp; &nbsp;<br> &nbsp;<br> &nbsp; &nbsp;return bResult;<br>}<br>×××××这是我翻译成DELPHI的代码,可是老有问题!×××××××<br>const<br> &nbsp;Method_Buffered &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 0;<br> &nbsp;File_Any_Access &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 0;<br> &nbsp;File_Device_Mass_Storage &nbsp; &nbsp; &nbsp; &nbsp;= $0000002D;<br> &nbsp;IOCTL_Storage_Base &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= File_Device_MASS_Storage;// $002D<br><br>type<br>// 存储设备的总线类型<br> &nbsp;pSTORAGE_BUS_TYPE=^STORAGE_BUS_TYPE;<br> &nbsp;STORAGE_BUS_TYPE =(<br> &nbsp; &nbsp;BusTypeUnknown = $00,<br> &nbsp; &nbsp;BusTypeScsi,<br> &nbsp; &nbsp;BusTypeAtapi,<br> &nbsp; &nbsp;BusTypeAta,<br> &nbsp; &nbsp;BusType1394,<br> &nbsp; &nbsp;BusTypeSsa,<br> &nbsp; &nbsp;BusTypeFibre,<br> &nbsp; &nbsp;BusTypeUsb,<br> &nbsp; &nbsp;BusTypeRAID,<br> &nbsp; &nbsp;BusTypeMaxReserved = $7F<br>);<br><br>// 查询存储设备属性的类型<br> pSTORAGE_QUERY_TYPe=^STORAGE_QUERY_TYPE;<br> &nbsp;STORAGE_QUERY_TYPE =(<br> &nbsp; &nbsp;PropertyStandardQuery = 0, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 读取描述<br> &nbsp; &nbsp;PropertyExistsQuery, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 测试是否支持<br> &nbsp; &nbsp;PropertyMaskQuery, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 读取指定的描述<br> &nbsp; &nbsp;PropertyQueryMaxDefined &nbsp; &nbsp; &nbsp; &nbsp;// 验证数据<br>);<br><br>// 查询存储设备还是适配器属性<br>pSTORAGE_PROPERTY_ID=^PSTORAGE_PROPERTY_ID;<br>STORAGE_PROPERTY_ID =(<br> &nbsp; &nbsp;StorageDeviceProperty = 0, // 查询设备属性<br> &nbsp; &nbsp;StorageAdapterProperty // 查询适配器属性<br>);<br><br>// 查询属性输入的数据结构<br>PSTORAGE_PROPERTY_QUERY=^STORAGE_PROPERTY_QUERY;<br>STORAGE_PROPERTY_QUERY = packed record<br> PropertyId:STORAGE_PROPERTY_ID ; // 设备/适配器<br> QueryType:STORAGE_QUERY_TYPE ; // 查询类型<br> &nbsp;AdditionalParameters:string[1]; // 额外的数据(仅定义了象征性的1个字节)<br>end;<br><br><br>// 查询属性输出的数据结构<br>PSTORAGE_DEVICE_DESCRIPTOR=^STORAGE_DEVICE_DESCRIPTOR;<br>STORAGE_DEVICE_DESCRIPTOR = packed record<br> &nbsp; &nbsp;Version:ULONG; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 版本<br> &nbsp; &nbsp;Size:ULONG; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 结构大小<br> &nbsp; &nbsp;DeviceType:UCHAR; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 设备类型<br> &nbsp; &nbsp;DeviceTypeModifier:UCHAR; &nbsp; &nbsp; &nbsp; &nbsp; // SCSI-2额外的设备类型<br> &nbsp; &nbsp;RemovableMedia:Boolean; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 是否可移动<br> &nbsp; &nbsp;CommandQueueing:Boolean; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 是否支持命令队列<br> &nbsp; &nbsp;VendorIdOffset:Ulong; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 厂家设定值的偏移<br> &nbsp; &nbsp;ProductIdOffset:ULONG; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 产品ID的偏移<br> &nbsp; &nbsp;ProductRevisionOffset:ULONG; &nbsp; &nbsp; &nbsp;// 产品版本的偏移<br> &nbsp; &nbsp;SerialNumberOffset:ULONG; &nbsp; &nbsp; &nbsp; &nbsp;// 序列号的偏移<br> &nbsp; &nbsp;BusType:STORAGE_BUS_TYPE ; &nbsp; &nbsp; &nbsp; &nbsp; // 总线类型<br> &nbsp; &nbsp;RawPropertiesLength:ULONG; &nbsp; &nbsp; &nbsp; // 额外的属性数据长度<br> &nbsp; &nbsp;RawDeviceProperties:string[1]; &nbsp; &nbsp; // 额外的属性数据(仅定义了象征性的1个字节)} STORAGE_DEVICE_DESCRIPTOR, *PSTORAGE_DEVICE_DESCRIPTOR;<br>end;<br><br>function GetDriveProperty(hDevice:Thandle;pDevDesc:PSTORAGE_DEVICE_DESCRIPTOR):Boolean;<br>function Ctl_Code(DeviceType, FuncNo, Method, Access: integer): integer;<br><br>implementation<br><br>function Ctl_Code(DeviceType, FuncNo, Method, Access: integer): integer;<br>begin<br> &nbsp;Result:= (DeviceType shl 16) or (Access shl 14) or (FuncNo shl 2) or (Method)<br>end;<br><br>function GetDriveProperty(hDevice:Thandle;pDevDesc:PSTORAGE_DEVICE_DESCRIPTOR):Boolean;<br>var<br> &nbsp; &nbsp;Query:STORAGE_PROPERTY_QUERY; &nbsp; &nbsp;// 查询输入参数<br> &nbsp; &nbsp;dwOutBytes:Dword; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// IOCTL输出数据长度<br> &nbsp; &nbsp;IOCTL_STORAGE_QUERY_PROPERTY:integer;<br>begin<br> &nbsp; &nbsp;// 指定查询方式<br> &nbsp; &nbsp;IOCTL_STORAGE_QUERY_PROPERTY:=Ctl_Code(IOCTL_STORAGE_BASE, $0500, METHOD_BUFFERED, FILE_ANY_ACCESS);<br> &nbsp; &nbsp;Query.PropertyId:= StorageDeviceProperty;<br> &nbsp; &nbsp;Query.QueryType:= PropertyStandardQuery;<br> &nbsp; &nbsp;Result:=DeviceIoControl(hDevice, // 设备句柄<br> &nbsp; &nbsp; &nbsp; &nbsp;IOCTL_STORAGE_QUERY_PROPERTY , &nbsp; &nbsp;// 取设备属性信息<br> &nbsp; &nbsp; &nbsp; &nbsp;@Query,<br> &nbsp; &nbsp; &nbsp; &nbsp;sizeof(Query), &nbsp; &nbsp; &nbsp; &nbsp;// 输入数据缓冲区<br> &nbsp; &nbsp; &nbsp; &nbsp;pDevDesc, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 输出数据缓冲区<br> &nbsp; &nbsp; &nbsp; &nbsp;pDevDesc.Size, &nbsp; &nbsp; &nbsp; &nbsp; // 输出数据长度<br> &nbsp; &nbsp; &nbsp; &nbsp;dwOutBytes,<br> &nbsp; &nbsp; &nbsp; &nbsp;nil); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 用同步I/O<br>end;<br>end.
 
请大家帮忙看一下我把C的代码转成DELPHI的时候那里有问题?<br>×××××这是我在网上查到的VC的代码××××××<br>// IOCTL控制码<br>#define IOCTL_STORAGE_QUERY_PROPERTY &nbsp; CTL_CODE(IOCTL_STORAGE_BASE, 0x0500, METHOD_BUFFERED, FILE_ANY_ACCESS)<br>// 存储设备的总线类型<br>typedef enum _STORAGE_BUS_TYPE {<br> &nbsp; &nbsp;BusTypeUnknown = 0x00,<br> &nbsp; &nbsp;BusTypeScsi,<br> &nbsp; &nbsp;BusTypeAtapi,<br> &nbsp; &nbsp;BusTypeAta,<br> &nbsp; &nbsp;BusType1394,<br> &nbsp; &nbsp;BusTypeSsa,<br> &nbsp; &nbsp;BusTypeFibre,<br> &nbsp; &nbsp;BusTypeUsb,<br> &nbsp; &nbsp;BusTypeRAID,<br> &nbsp; &nbsp;BusTypeMaxReserved = 0x7F<br>} STORAGE_BUS_TYPE, *PSTORAGE_BUS_TYPE;<br> &nbsp;<br>// 查询存储设备属性的类型<br>typedef enum _STORAGE_QUERY_TYPE {<br> &nbsp; &nbsp;PropertyStandardQuery = 0, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 读取描述<br> &nbsp; &nbsp;PropertyExistsQuery, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 测试是否支持<br> &nbsp; &nbsp;PropertyMaskQuery, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 读取指定的描述<br> &nbsp; &nbsp;PropertyQueryMaxDefined &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 验证数据<br>} STORAGE_QUERY_TYPE, *PSTORAGE_QUERY_TYPE;<br> &nbsp;<br>// 查询存储设备还是适配器属性<br>typedef enum _STORAGE_PROPERTY_ID {<br> &nbsp; &nbsp;StorageDeviceProperty = 0, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 查询设备属性<br> &nbsp; &nbsp;StorageAdapterProperty &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 查询适配器属性<br>} STORAGE_PROPERTY_ID, *PSTORAGE_PROPERTY_ID;<br> &nbsp;<br>// 查询属性输入的数据结构<br>typedef struct _STORAGE_PROPERTY_QUERY {<br> &nbsp; &nbsp;STORAGE_PROPERTY_ID PropertyId; &nbsp; &nbsp; // 设备/适配器<br> &nbsp; &nbsp;STORAGE_QUERY_TYPE QueryType; &nbsp; &nbsp; &nbsp; // 查询类型 <br> &nbsp; &nbsp;UCHAR AdditionalParameters[1]; &nbsp; &nbsp; &nbsp;// 额外的数据(仅定义了象征性的1个字节)<br>} STORAGE_PROPERTY_QUERY, *PSTORAGE_PROPERTY_QUERY;<br> &nbsp;<br>// 查询属性输出的数据结构<br>typedef struct _STORAGE_DEVICE_DESCRIPTOR {<br> &nbsp; &nbsp;ULONG Version; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 版本<br> &nbsp; &nbsp;ULONG Size; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 结构大小<br> &nbsp; &nbsp;UCHAR DeviceType; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 设备类型<br> &nbsp; &nbsp;UCHAR DeviceTypeModifier; &nbsp; &nbsp; &nbsp; &nbsp; // SCSI-2额外的设备类型<br> &nbsp; &nbsp;BOOLEAN RemovableMedia; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 是否可移动<br> &nbsp; &nbsp;BOOLEAN CommandQueueing; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 是否支持命令队列<br> &nbsp; &nbsp;ULONG VendorIdOffset; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 厂家设定值的偏移<br> &nbsp; &nbsp;ULONG ProductIdOffset; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 产品ID的偏移<br> &nbsp; &nbsp;ULONG ProductRevisionOffset; &nbsp; &nbsp; &nbsp;// 产品版本的偏移<br> &nbsp; &nbsp;ULONG SerialNumberOffset; &nbsp; &nbsp; &nbsp; &nbsp; // 序列号的偏移<br> &nbsp; &nbsp;STORAGE_BUS_TYPE BusType; &nbsp; &nbsp; &nbsp; &nbsp; // 总线类型<br> &nbsp; &nbsp;ULONG RawPropertiesLength; &nbsp; &nbsp; &nbsp; &nbsp;// 额外的属性数据长度<br> &nbsp; &nbsp;UCHAR RawDeviceProperties[1]; &nbsp; &nbsp; // 额外的属性数据(仅定义了象征性的1个字节)<br>} STORAGE_DEVICE_DESCRIPTOR, *PSTORAGE_DEVICE_DESCRIPTOR;<br> &nbsp;<br>// 取设备属性信息<br>// hDevice -- 设备句柄<br>// pDevDesc -- 输出的设备描述和属性信息缓冲区指针(包含连接在一起的两部分)<br>BOOL GetDriveProperty(HANDLE hDevice, PSTORAGE_DEVICE_DESCRIPTOR pDevDesc)<br>{<br> &nbsp; &nbsp;STORAGE_PROPERTY_QUERY Query; &nbsp; &nbsp;// 查询输入参数<br> &nbsp; &nbsp;DWORD dwOutBytes; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// IOCTL输出数据长度<br> &nbsp; &nbsp;BOOL bResult; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// IOCTL返回值<br> &nbsp;<br> &nbsp; &nbsp;// 指定查询方式<br> &nbsp; &nbsp;Query.PropertyId = StorageDeviceProperty;<br> &nbsp; &nbsp;Query.QueryType = PropertyStandardQuery;<br> &nbsp;<br> &nbsp; &nbsp;// 用IOCTL_STORAGE_QUERY_PROPERTY取设备属性信息<br> &nbsp; &nbsp;bResult = ::DeviceIoControl(hDevice, // 设备句柄<br> &nbsp; &nbsp; &nbsp; &nbsp;IOCTL_STORAGE_QUERY_PROPERTY, &nbsp; &nbsp;// 取设备属性信息<br> &nbsp; &nbsp; &nbsp; &nbsp;&amp;Query, sizeof(STORAGE_PROPERTY_QUERY), &nbsp; &nbsp;// 输入数据缓冲区<br> &nbsp; &nbsp; &nbsp; &nbsp;pDevDesc, pDevDesc-&gt;Size, &nbsp; &nbsp; &nbsp; &nbsp;// 输出数据缓冲区<br> &nbsp; &nbsp; &nbsp; &nbsp;&amp;dwOutBytes, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 输出数据长度<br> &nbsp; &nbsp; &nbsp; &nbsp;(LPOVERLAPPED)NULL); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 用同步I/O &nbsp; &nbsp;<br> &nbsp;<br> &nbsp; &nbsp;return bResult;<br>}<br>×××××这是我翻译成DELPHI的代码,可是老有问题!×××××××<br>const<br> &nbsp;Method_Buffered &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 0;<br> &nbsp;File_Any_Access &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 0;<br> &nbsp;File_Device_Mass_Storage &nbsp; &nbsp; &nbsp; &nbsp;= $0000002D;<br> &nbsp;IOCTL_Storage_Base &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= File_Device_MASS_Storage;// $002D<br><br>type<br>// 存储设备的总线类型<br> &nbsp;pSTORAGE_BUS_TYPE=^STORAGE_BUS_TYPE;<br> &nbsp;STORAGE_BUS_TYPE =(<br> &nbsp; &nbsp;BusTypeUnknown = $00,<br> &nbsp; &nbsp;BusTypeScsi,<br> &nbsp; &nbsp;BusTypeAtapi,<br> &nbsp; &nbsp;BusTypeAta,<br> &nbsp; &nbsp;BusType1394,<br> &nbsp; &nbsp;BusTypeSsa,<br> &nbsp; &nbsp;BusTypeFibre,<br> &nbsp; &nbsp;BusTypeUsb,<br> &nbsp; &nbsp;BusTypeRAID,<br> &nbsp; &nbsp;BusTypeMaxReserved = $7F<br>);<br><br>// 查询存储设备属性的类型<br> pSTORAGE_QUERY_TYPe=^STORAGE_QUERY_TYPE;<br> &nbsp;STORAGE_QUERY_TYPE =(<br> &nbsp; &nbsp;PropertyStandardQuery = 0, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 读取描述<br> &nbsp; &nbsp;PropertyExistsQuery, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 测试是否支持<br> &nbsp; &nbsp;PropertyMaskQuery, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 读取指定的描述<br> &nbsp; &nbsp;PropertyQueryMaxDefined &nbsp; &nbsp; &nbsp; &nbsp;// 验证数据<br>);<br><br>// 查询存储设备还是适配器属性<br>pSTORAGE_PROPERTY_ID=^PSTORAGE_PROPERTY_ID;<br>STORAGE_PROPERTY_ID =(<br> &nbsp; &nbsp;StorageDeviceProperty = 0, // 查询设备属性<br> &nbsp; &nbsp;StorageAdapterProperty // 查询适配器属性<br>);<br><br>// 查询属性输入的数据结构<br>PSTORAGE_PROPERTY_QUERY=^STORAGE_PROPERTY_QUERY;<br>STORAGE_PROPERTY_QUERY = packed record<br> PropertyId:STORAGE_PROPERTY_ID ; // 设备/适配器<br> QueryType:STORAGE_QUERY_TYPE ; // 查询类型<br> &nbsp;AdditionalParameters:string[1]; // 额外的数据(仅定义了象征性的1个字节)<br>end;<br><br><br>// 查询属性输出的数据结构<br>PSTORAGE_DEVICE_DESCRIPTOR=^STORAGE_DEVICE_DESCRIPTOR;<br>STORAGE_DEVICE_DESCRIPTOR = packed record<br> &nbsp; &nbsp;Version:ULONG; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 版本<br> &nbsp; &nbsp;Size:ULONG; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 结构大小<br> &nbsp; &nbsp;DeviceType:UCHAR; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 设备类型<br> &nbsp; &nbsp;DeviceTypeModifier:UCHAR; &nbsp; &nbsp; &nbsp; &nbsp; // SCSI-2额外的设备类型<br> &nbsp; &nbsp;RemovableMedia:Boolean; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 是否可移动<br> &nbsp; &nbsp;CommandQueueing:Boolean; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 是否支持命令队列<br> &nbsp; &nbsp;VendorIdOffset:Ulong; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 厂家设定值的偏移<br> &nbsp; &nbsp;ProductIdOffset:ULONG; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 产品ID的偏移<br> &nbsp; &nbsp;ProductRevisionOffset:ULONG; &nbsp; &nbsp; &nbsp;// 产品版本的偏移<br> &nbsp; &nbsp;SerialNumberOffset:ULONG; &nbsp; &nbsp; &nbsp; &nbsp;// 序列号的偏移<br> &nbsp; &nbsp;BusType:STORAGE_BUS_TYPE ; &nbsp; &nbsp; &nbsp; &nbsp; // 总线类型<br> &nbsp; &nbsp;RawPropertiesLength:ULONG; &nbsp; &nbsp; &nbsp; // 额外的属性数据长度<br> &nbsp; &nbsp;RawDeviceProperties:string[1]; &nbsp; &nbsp; // 额外的属性数据(仅定义了象征性的1个字节)} STORAGE_DEVICE_DESCRIPTOR, *PSTORAGE_DEVICE_DESCRIPTOR;<br>end;<br><br>function GetDriveProperty(hDevice:Thandle;pDevDesc:PSTORAGE_DEVICE_DESCRIPTOR):Boolean;<br>function Ctl_Code(DeviceType, FuncNo, Method, Access: integer): integer;<br><br>implementation<br><br>function Ctl_Code(DeviceType, FuncNo, Method, Access: integer): integer;<br>begin<br> &nbsp;Result:= (DeviceType shl 16) or (Access shl 14) or (FuncNo shl 2) or (Method)<br>end;<br><br>function GetDriveProperty(hDevice:Thandle;pDevDesc:PSTORAGE_DEVICE_DESCRIPTOR):Boolean;<br>var<br> &nbsp; &nbsp;Query:STORAGE_PROPERTY_QUERY; &nbsp; &nbsp;// 查询输入参数<br> &nbsp; &nbsp;dwOutBytes:Dword; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// IOCTL输出数据长度<br> &nbsp; &nbsp;IOCTL_STORAGE_QUERY_PROPERTY:integer;<br>begin<br> &nbsp; &nbsp;// 指定查询方式<br> &nbsp; &nbsp;IOCTL_STORAGE_QUERY_PROPERTY:=Ctl_Code(IOCTL_STORAGE_BASE, $0500, METHOD_BUFFERED, FILE_ANY_ACCESS);<br> &nbsp; &nbsp;Query.PropertyId:= StorageDeviceProperty;<br> &nbsp; &nbsp;Query.QueryType:= PropertyStandardQuery;<br> &nbsp; &nbsp;Result:=DeviceIoControl(hDevice, // 设备句柄<br> &nbsp; &nbsp; &nbsp; &nbsp;IOCTL_STORAGE_QUERY_PROPERTY , &nbsp; &nbsp;// 取设备属性信息<br> &nbsp; &nbsp; &nbsp; &nbsp;@Query,<br> &nbsp; &nbsp; &nbsp; &nbsp;sizeof(Query), &nbsp; &nbsp; &nbsp; &nbsp;// 输入数据缓冲区<br> &nbsp; &nbsp; &nbsp; &nbsp;pDevDesc, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 输出数据缓冲区<br> &nbsp; &nbsp; &nbsp; &nbsp;pDevDesc.Size, &nbsp; &nbsp; &nbsp; &nbsp; // 输出数据长度<br> &nbsp; &nbsp; &nbsp; &nbsp;dwOutBytes,<br> &nbsp; &nbsp; &nbsp; &nbsp;nil); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 用同步I/O<br>end;<br>end.
 
没有熟悉C和DELPHI的朋友吗?我在CSDN上问了好几天都没人回答,难道大富翁上也没有?<br>这个对熟悉C的朋友应该很简单啊。
 
初步觉得enum才需要packed
 
把调用的调试代码放出来下,因为我不指导前面那个Handle应该传什么参数,一起调看看
 
哦,HANDLE调用的是CREATEFILE()返回的句柄,就是打开磁盘的句柄。<br>//////////////////////////调用代码<br>var<br> &nbsp;Dev:PSTORAGE_DEVICE_DESCRIPTOR;<br> &nbsp;H:THandle;<br>begin<br>try<br> &nbsp;h:=CreateFile(pchar('//./PhysicalDrive0'),<br> &nbsp; &nbsp; &nbsp; &nbsp;GENERIC_READ, FILE_SHARE_READ OR FILE_SHARE_WRITE,<br> &nbsp; &nbsp; &nbsp; &nbsp;nil, OPEN_EXISTING, 0, 0);<br><br>ShowMessage(IntToStr(h));<br>if GetDriveProperty(h,Dev) then ShowMessage('3é1|');<br>finally<br> &nbsp;CloseHandle(H);<br>end;
 
大家不要看我得问题这么长,^_^,其实比较简单啊。希望大家积极帮忙!
 
unit uUtils;<br><br>interface<br><br>uses<br> &nbsp; &nbsp;Windows, Dialogs, SysUtils;<br><br>const<br> &nbsp; &nbsp;Method_Buffered = 0;<br> &nbsp; &nbsp;File_Any_Access = 0;<br> &nbsp; &nbsp;File_Device_Mass_Storage = $0000002D;<br> &nbsp; &nbsp;IOCTL_Storage_Base = File_Device_Mass_Storage; // $002D<br><br>type<br> &nbsp; &nbsp;// 存储设备的总线类型<br> &nbsp; &nbsp;PSTORAGE_BUS_TYPE = ^STORAGE_BUS_TYPE;<br> &nbsp; &nbsp;STORAGE_BUS_TYPE = (BusTypeUnknown = $00, BusTypeScsi,<br> &nbsp; &nbsp; &nbsp; &nbsp;BusTypeAtapi, BusTypeAta,<br> &nbsp; &nbsp; &nbsp; &nbsp;BusType1394, BusTypeSsa,<br> &nbsp; &nbsp; &nbsp; &nbsp;BusTypeFibre, BusTypeUsb,<br> &nbsp; &nbsp; &nbsp; &nbsp;BusTypeRAID, BusTypeMaxReserved = $7F);<br><br> &nbsp; &nbsp;// 查询存储设备属性的类型<br> &nbsp; &nbsp;PSTORAGE_QUERY_TYPE = ^STORAGE_QUERY_TYPE;<br> &nbsp; &nbsp;STORAGE_QUERY_TYPE = (<br> &nbsp; &nbsp; &nbsp; &nbsp;PropertyStandardQuery = 0, // 读取描述<br> &nbsp; &nbsp; &nbsp; &nbsp;PropertyExistsQuery, // 测试是否支持<br> &nbsp; &nbsp; &nbsp; &nbsp;PropertyMaskQuery, // 读取指定的描述<br> &nbsp; &nbsp; &nbsp; &nbsp;PropertyQueryMaxDefined // 验证数据<br> &nbsp; &nbsp; &nbsp; &nbsp;);<br><br> &nbsp; &nbsp;// 查询存储设备还是适配器属性<br> &nbsp; &nbsp;PSTORAGE_PROPERTY_ID = ^STORAGE_PROPERTY_ID;<br> &nbsp; &nbsp;STORAGE_PROPERTY_ID = (<br> &nbsp; &nbsp; &nbsp; &nbsp;StorageDeviceProperty = 0, // 查询设备属性<br> &nbsp; &nbsp; &nbsp; &nbsp;StorageAdapterProperty // 查询适配器属性<br> &nbsp; &nbsp; &nbsp; &nbsp;);<br><br> &nbsp; &nbsp;// 查询属性输入的数据结构<br> &nbsp; &nbsp;PSTORAGE_PROPERTY_QUERY = ^STORAGE_PROPERTY_QUERY;<br> &nbsp; &nbsp;STORAGE_PROPERTY_QUERY = record<br> &nbsp; &nbsp; &nbsp; &nbsp;PropertyId: STORAGE_PROPERTY_ID; // 设备/适配器<br> &nbsp; &nbsp; &nbsp; &nbsp;QueryType: STORAGE_QUERY_TYPE; // 查询类型<br> &nbsp; &nbsp; &nbsp; &nbsp;AdditionalParameters: array[0..0] of UCHAR; // 额外的数据(仅定义了象征性的1个字节)<br> &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp;// 查询属性输出的数据结构<br> &nbsp; &nbsp;PSTORAGE_DEVICE_DESCRIPTOR = ^STORAGE_DEVICE_DESCRIPTOR;<br> &nbsp; &nbsp;STORAGE_DEVICE_DESCRIPTOR = record<br> &nbsp; &nbsp; &nbsp; &nbsp;Version: ULONG; // 版本<br> &nbsp; &nbsp; &nbsp; &nbsp;Size: ULONG; // 结构大小<br> &nbsp; &nbsp; &nbsp; &nbsp;DeviceType: UCHAR; // 设备类型<br> &nbsp; &nbsp; &nbsp; &nbsp;DeviceTypeModifier: UCHAR; // SCSI-2额外的设备类型<br> &nbsp; &nbsp; &nbsp; &nbsp;RemovableMedia: Boolean; // 是否可移动<br> &nbsp; &nbsp; &nbsp; &nbsp;CommandQueueing: Boolean; // 是否支持命令队列<br> &nbsp; &nbsp; &nbsp; &nbsp;VendorIdOffset: ULONG; // 厂家设定值的偏移<br> &nbsp; &nbsp; &nbsp; &nbsp;ProductIdOffset: ULONG; // 产品ID的偏移<br> &nbsp; &nbsp; &nbsp; &nbsp;ProductRevisionOffset: ULONG; // 产品版本的偏移<br> &nbsp; &nbsp; &nbsp; &nbsp;SerialNumberOffset: ULONG; // 序列号的偏移<br> &nbsp; &nbsp; &nbsp; &nbsp;BusType: STORAGE_BUS_TYPE; // 总线类型<br> &nbsp; &nbsp; &nbsp; &nbsp;RawPropertiesLength: ULONG; // 额外的属性数据长度<br> &nbsp; &nbsp; &nbsp; &nbsp;RawDeviceProperties: array[0..0] of UCHAR; // 额外的属性数据(仅定义了象征性的1个字节)<br> &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp;// 取设备属性信息<br> &nbsp; &nbsp;// hDevice -- 设备句柄<br> &nbsp; &nbsp;// pDevDesc -- 输出的设备描述和属性信息缓冲区指针(包含连接在一起的两部分)<br>function GetDriveProperty(hDevice: THandle; pDevDesc: PSTORAGE_DEVICE_DESCRIPTOR): Boolean;<br>function Ctl_Code(DeviceType, FuncNo, Method, Access: integer): integer;<br><br>implementation<br><br>function Ctl_Code(DeviceType, FuncNo, Method, Access: integer): integer;<br>begin<br> &nbsp; &nbsp;Result := (DeviceType shl 16) or (Access shl 14) or (FuncNo shl 2) or (Method)<br>end;<br><br>function GetDriveProperty(hDevice: THandle; pDevDesc: PSTORAGE_DEVICE_DESCRIPTOR): Boolean;<br>var<br> &nbsp; &nbsp;Query: STORAGE_PROPERTY_QUERY; // 查询输入参数<br> &nbsp; &nbsp;dwOutBytes: DWORD; // IOCTL输出数据长度<br> &nbsp; &nbsp;bResult: Boolean; // IOCTL返回值<br> &nbsp; &nbsp;IOCTL_STORAGE_QUERY_PROPERTY: Integer;<br> &nbsp; &nbsp;nError : Integer;<br>begin<br> &nbsp; &nbsp;// 指定查询方式<br> &nbsp; &nbsp;IOCTL_STORAGE_QUERY_PROPERTY := Ctl_Code(IOCTL_Storage_Base, $0500, Method_Buffered, File_Any_Access);<br> &nbsp; &nbsp;Query.PropertyId := StorageDeviceProperty;<br> &nbsp; &nbsp;Query.QueryType := PropertyStandardQuery;<br><br> &nbsp; &nbsp;// 用IOCTL_STORAGE_QUERY_PROPERTY取设备属性信息<br> &nbsp; &nbsp;bResult := DeviceIoControl(hDevice, // 设备句柄<br> &nbsp; &nbsp; &nbsp; &nbsp;IOCTL_STORAGE_QUERY_PROPERTY, // 取设备属性信息<br> &nbsp; &nbsp; &nbsp; &nbsp;@Query, sizeof(STORAGE_PROPERTY_QUERY), // 输入数据缓冲区<br> &nbsp; &nbsp; &nbsp; &nbsp;pDevDesc, pDevDesc.Size, // 输出数据缓冲区<br> &nbsp; &nbsp; &nbsp; &nbsp;dwOutBytes, // 输出数据长度<br> &nbsp; &nbsp; &nbsp; &nbsp;nil); // 用同步I/O<br> &nbsp; &nbsp;nError := GetLastError;<br> &nbsp; &nbsp;if nError &gt;0 then ShowMessage(InttoStr(nError));// 提示是“内存位置访问无效”<br> &nbsp; &nbsp;Result := bResult;<br>end;<br><br>end.<br><br>暂时修改到这里,但是还有问题,继续关注
 
还是有错误,无法完成DEVICEIOCONTROL.^_^希望继续关注!
 
错误提示是Error_NoAccess。<br>if nError=Error_NoAccess then ShowMessage(InttoStr(nError));
 
http://www.csdn.net/develop/author/bhw98/StorageEnum.zip这是VC的代码。请chenybin同志参考一下。<br><br>DeviceIoControl(hDevice, // 设备句柄<br> &nbsp; &nbsp; &nbsp; &nbsp;IOCTL_STORAGE_QUERY_PROPERTY, // 2954240 这个没有问题,我在VC下测试通过。<br> &nbsp; &nbsp; &nbsp; &nbsp;@Query, sizeof(STORAGE_PROPERTY_QUERY), // 输入数据缓冲区<br> &nbsp; &nbsp; &nbsp; &nbsp;pDevDesc, pDevDesc.Size, // 输出数据缓冲区<br> &nbsp; &nbsp; &nbsp; &nbsp;dwOutBytes, // 输出数据长度<br> &nbsp; &nbsp; &nbsp; &nbsp;nil); // 用同步I/O
 
放弃了,实在搞不定:(<br><br>unit uUtils;<br><br>interface<br><br>uses<br> &nbsp; &nbsp;Windows, Dialogs, SysUtils;<br><br>const<br> &nbsp; &nbsp;Method_Buffered = 0;<br> &nbsp; &nbsp;File_Any_Access = 0;<br> &nbsp; &nbsp;File_Device_Mass_Storage = $0000002D;<br> &nbsp; &nbsp;IOCTL_Storage_Base = File_Device_Mass_Storage; // $002D<br><br>type<br> &nbsp; &nbsp;// 存储设备的总线类型<br> &nbsp; &nbsp;PSTORAGE_BUS_TYPE = ^STORAGE_BUS_TYPE;<br> &nbsp; &nbsp;STORAGE_BUS_TYPE = (BusTypeUnknown = $00, BusTypeScsi,<br> &nbsp; &nbsp; &nbsp; &nbsp;BusTypeAtapi, BusTypeAta,<br> &nbsp; &nbsp; &nbsp; &nbsp;BusType1394, BusTypeSsa,<br> &nbsp; &nbsp; &nbsp; &nbsp;BusTypeFibre, BusTypeUsb,<br> &nbsp; &nbsp; &nbsp; &nbsp;BusTypeRAID, BusTypeMaxReserved = $7F);<br><br> &nbsp; &nbsp;// 查询存储设备属性的类型<br> &nbsp; &nbsp;PSTORAGE_QUERY_TYPE = ^STORAGE_QUERY_TYPE;<br> &nbsp; &nbsp;STORAGE_QUERY_TYPE = (<br> &nbsp; &nbsp; &nbsp; &nbsp;PropertyStandardQuery = 0, // 读取描述<br> &nbsp; &nbsp; &nbsp; &nbsp;PropertyExistsQuery, // 测试是否支持<br> &nbsp; &nbsp; &nbsp; &nbsp;PropertyMaskQuery, // 读取指定的描述<br> &nbsp; &nbsp; &nbsp; &nbsp;PropertyQueryMaxDefined // 验证数据<br> &nbsp; &nbsp; &nbsp; &nbsp;);<br><br> &nbsp; &nbsp;// 查询存储设备还是适配器属性<br> &nbsp; &nbsp;PSTORAGE_PROPERTY_ID = ^STORAGE_PROPERTY_ID;<br> &nbsp; &nbsp;STORAGE_PROPERTY_ID = (<br> &nbsp; &nbsp; &nbsp; &nbsp;StorageDeviceProperty = 0, // 查询设备属性<br> &nbsp; &nbsp; &nbsp; &nbsp;StorageAdapterProperty // 查询适配器属性<br> &nbsp; &nbsp; &nbsp; &nbsp;);<br><br> &nbsp; &nbsp;// 查询属性输入的数据结构<br> &nbsp; &nbsp;PSTORAGE_PROPERTY_QUERY = ^STORAGE_PROPERTY_QUERY;<br> &nbsp; &nbsp;STORAGE_PROPERTY_QUERY = record<br> &nbsp; &nbsp; &nbsp; &nbsp;PropertyId: STORAGE_PROPERTY_ID; // 设备/适配器<br> &nbsp; &nbsp; &nbsp; &nbsp;QueryType: STORAGE_QUERY_TYPE; // 查询类型<br> &nbsp; &nbsp; &nbsp; &nbsp;AdditionalParameters: array[0..0] of UCHAR; // 额外的数据(仅定义了象征性的1个字节)<br> &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp;// 查询属性输出的数据结构<br> &nbsp; &nbsp;PSTORAGE_DEVICE_DESCRIPTOR = ^STORAGE_DEVICE_DESCRIPTOR;<br> &nbsp; &nbsp;STORAGE_DEVICE_DESCRIPTOR = record<br> &nbsp; &nbsp; &nbsp; &nbsp;Version: ULONG; // 版本<br> &nbsp; &nbsp; &nbsp; &nbsp;Size: ULONG; // 结构大小<br> &nbsp; &nbsp; &nbsp; &nbsp;DeviceType: UCHAR; // 设备类型<br> &nbsp; &nbsp; &nbsp; &nbsp;DeviceTypeModifier: UCHAR; // SCSI-2额外的设备类型<br> &nbsp; &nbsp; &nbsp; &nbsp;RemovableMedia: Boolean; // 是否可移动<br> &nbsp; &nbsp; &nbsp; &nbsp;CommandQueueing: Boolean; // 是否支持命令队列<br> &nbsp; &nbsp; &nbsp; &nbsp;VendorIdOffset: ULONG; // 厂家设定值的偏移<br> &nbsp; &nbsp; &nbsp; &nbsp;ProductIdOffset: ULONG; // 产品ID的偏移<br> &nbsp; &nbsp; &nbsp; &nbsp;ProductRevisionOffset: ULONG; // 产品版本的偏移<br> &nbsp; &nbsp; &nbsp; &nbsp;SerialNumberOffset: ULONG; // 序列号的偏移<br> &nbsp; &nbsp; &nbsp; &nbsp;BusType: STORAGE_BUS_TYPE; // 总线类型<br> &nbsp; &nbsp; &nbsp; &nbsp;RawPropertiesLength: ULONG; // 额外的属性数据长度<br> &nbsp; &nbsp; &nbsp; &nbsp;RawDeviceProperties: array[0..0] of UCHAR; // 额外的属性数据(仅定义了象征性的1个字节)<br> &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp;// 取设备属性信息<br> &nbsp; &nbsp;// hDevice -- 设备句柄<br> &nbsp; &nbsp;// pDevDesc -- 输出的设备描述和属性信息缓冲区指针(包含连接在一起的两部分)<br>function GetDriveProperty(hDevice: THandle; pDevDesc: PSTORAGE_DEVICE_DESCRIPTOR): Boolean;<br>function Ctl_Code(DeviceType, FuncNo, Method, Access: integer): integer;<br><br>implementation<br><br>function Ctl_Code(DeviceType, FuncNo, Method, Access: integer): integer;<br>begin<br> &nbsp; &nbsp;Result := (DeviceType shl 16) or (Access shl 14) or (FuncNo shl 2) or (Method)<br>end;<br><br>function GetDriveProperty(hDevice: THandle; pDevDesc: PSTORAGE_DEVICE_DESCRIPTOR): Boolean;<br>var<br> &nbsp; &nbsp;Query: STORAGE_PROPERTY_QUERY; // 查询输入参数<br> &nbsp; &nbsp;dwOutBytes: DWORD; // IOCTL输出数据长度<br> &nbsp; &nbsp;bResult: Boolean; // IOCTL返回值<br> &nbsp; &nbsp;IOCTL_STORAGE_QUERY_PROPERTY: Integer;<br> &nbsp; &nbsp;nError : Integer;<br>begin<br> &nbsp; &nbsp;// 指定查询方式<br> &nbsp; &nbsp;IOCTL_STORAGE_QUERY_PROPERTY := Ctl_Code(IOCTL_Storage_Base, $0500, Method_Buffered, File_Any_Access);<br> &nbsp; &nbsp;Query.PropertyId := StorageDeviceProperty;<br> &nbsp; &nbsp;Query.QueryType := PropertyStandardQuery;<br> &nbsp; &nbsp;dwOutBytes := 0;<br> &nbsp; &nbsp;// 用IOCTL_STORAGE_QUERY_PROPERTY取设备属性信息<br> &nbsp; &nbsp;bResult := DeviceIoControl(hDevice, // 设备句柄<br> &nbsp; &nbsp; &nbsp; &nbsp;IOCTL_STORAGE_QUERY_PROPERTY, // 取设备属性信息<br> &nbsp; &nbsp; &nbsp; &nbsp;@Query, sizeof(STORAGE_PROPERTY_QUERY), // 输入数据缓冲区<br> &nbsp; &nbsp; &nbsp; &nbsp;pDevDesc, pDevDesc.Size, // 输出数据缓冲区<br> &nbsp; &nbsp; &nbsp; &nbsp;dwOutBytes, // 输出数据长度<br> &nbsp; &nbsp; &nbsp; &nbsp;nil); // 用同步I/O<br> &nbsp; &nbsp;nError := GetLastError;<br> &nbsp; &nbsp;if nError &gt;0 then ShowMessage(InttoStr(nError));// 提示是“内存位置访问无效”<br> &nbsp; &nbsp;Result := bResult;<br>end;<br><br>end.<br><br><br><br>unit Main;<br><br>interface<br><br>uses<br> &nbsp; &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp; &nbsp;Dialogs, uUtils, StdCtrls;<br><br>type<br> &nbsp; &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp; &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp; &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp; &nbsp;private<br> &nbsp; &nbsp; &nbsp; &nbsp;{ Private declarations }<br> &nbsp; &nbsp;public<br> &nbsp; &nbsp; &nbsp; &nbsp;{ Public declarations }<br> &nbsp; &nbsp;end;<br><br>var<br> &nbsp; &nbsp;Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> &nbsp; &nbsp;Dev: PSTORAGE_DEVICE_DESCRIPTOR;<br> &nbsp; &nbsp;H: THandle;<br>begin<br> &nbsp; &nbsp;H := CreateFile(pchar('//./PhysicalDrive0'),<br> &nbsp; &nbsp; &nbsp; &nbsp;GENERIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE,<br> &nbsp; &nbsp; &nbsp; &nbsp;nil, OPEN_EXISTING, 0, 0);<br> &nbsp; &nbsp;try<br> &nbsp; &nbsp; &nbsp; &nbsp;if H &lt;&gt; INVALID_HANDLE_VALUE then begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetMem(Dev, sizeof(STORAGE_DEVICE_DESCRIPTOR) + 512 - 1);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dev.Size := sizeof(STORAGE_DEVICE_DESCRIPTOR) + 512 - 1;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if GetDriveProperty(H, Dev) then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ShowMessage('3é1|');<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FreeMem(Dev, sizeof(STORAGE_DEVICE_DESCRIPTOR) + 512 - 1);<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;finally<br> &nbsp; &nbsp; &nbsp; &nbsp;CloseHandle(H);<br> &nbsp; &nbsp;end;<br>end;<br><br><br>end.<br><br>老是提示说参数错误,郁闷
 
bResult := DeviceIoControl(hDevice, // 设备句柄<br> &nbsp; &nbsp; &nbsp; &nbsp;IOCTL_STORAGE_QUERY_PROPERTY, // 取设备属性信息<br> &nbsp; &nbsp; &nbsp; &nbsp;@Query, sizeof(STORAGE_PROPERTY_QUERY), // 输入数据缓冲区<br> &nbsp; &nbsp; &nbsp; &nbsp;pDevDesc, pDevDesc.Size, // 输出数据缓冲区<br> &nbsp; &nbsp; &nbsp; &nbsp;dwOutBytes, // 输出数据长度<br> &nbsp; &nbsp; &nbsp; &nbsp;nil); // 用同步I/O<br> &nbsp; &nbsp;nError := GetLastError;<br><br><br>这里,如果我把sizeof(STORAGE_PROPERTY_QUERY)修改成12就可以了,12是从VC里面找出来的,说明我上面的定义有问题,其他基本正常
 
兄弟,回答得这么辛苦,能不能加点分啊[:(][:(][:(]
 
当然可以,我把所有的分都给你!
 
我现在只有170分了,回头给你!!!万分感谢chenybin!!
 
还是有问题阿。晕阿!
 
惭愧惭愧,搞了几天都没弄出来,和VC里面的参数对比好像就是Handle的问题,是不是我们调用的那个Handle有问题呢,因为现在的结果上dwOutBytes始终为0
 
不应该阿,我用VC写了一个DLL,传递的参数是handle,总算可以用了。哈哈
 
感觉还是Handle的问题,VC里面每次Handle都是一样的,DELPHI里面也是,怎么两个就是不同呢,奇怪
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
2K
import
I
D
回复
0
查看
2K
DelphiTeacher的专栏
D
I
回复
0
查看
964
import
I
后退
顶部