Setupdixxx deviceiocontrol 获取硬盘大小,硬盘序列号

本文介绍了修复设备控制代码的过程,通过DeviceIoControl函数来获取硬盘的大小信息。修复后的代码能够正确累加分区长度,从而得到完整的硬盘容量。对于硬盘序列号的获取也进行了相应说明。
摘要由CSDN通过智能技术生成
HDEVINFO                         hDevInfo;
			SP_DEVICE_INTERFACE_DATA         DevIntfData;
			PSP_DEVICE_INTERFACE_DETAIL_DATA DevIntfDetailData;
			SP_DEVINFO_DATA                  DevData;

			DWORD dwSize, dwMemberIdx;

			// We will try to get device information set for all USB devices that have a
			// device interface and are currently present on the system (plugged in).
			hDevInfo = SetupDiGetClassDevs(
				&DiskClassGuid, NULL, 0, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);

			if (hDevInfo != INVALID_HANDLE_VALUE)
			{
				// Prepare to enumerate all device interfaces for the device information
				// set that we retrieved with SetupDiGetClassDevs(..)
				DevIntfData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
				dwMemberIdx = 0;

				// Next, we will keep calling this SetupDiEnumDeviceInterfaces(..) until this
				// function causes GetLastError() to return  ERROR_NO_MORE_ITEMS. With each
				// call the dwMemberIdx value needs to be incremented to retrieve the next
				// device interface information.

				SetupDiEnumDeviceInterfaces(hDevInfo, NULL, &DiskClassGuid,
					dwMemberIdx, &DevIntfData);

				while (GetLastError() != ERROR_NO_MORE_ITEMS)
				{
					// As a last step we will need to get some more details for each
					// of device interface information we are able to retrieve. This
					// device interface detail gives us the information we need to identify
					// the device (VID/PID), and decide if it's useful to us. It will also
					// provide a DEVINFO_DATA structure which we can use to know the serial
					// port name for a virtual com port.

					DevData.cbSize = sizeof(DevData);

					// Get the required buffer size. Call SetupDiGetDeviceInterface
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值