[英]Find all logical drives from a unitmask
I have wrote a program to detect usb drive whenever it is inserted.我编写了一个程序来检测 usb 驱动器插入时的情况。 I want to know all the partitions on the usb.我想知道 usb 上的所有分区。 If my drive has one partition (example E:/
), then the program detects successfully.如果我的驱动器有一个分区(例如E:/
),则程序检测成功。 But if the usb drive has two partition (example: E:
, F:
) then only first partition E:
is detected but I do not know how to detect F:
or other partitions of the usb.但是如果usb驱动器有两个分区(例如: E:
, F:
:),那么只检测到第一个分区E:
但我不知道如何检测F:
或usb的其他分区。 On inserting a usb drive, DBT_DEVICEARRIVAL
is triggered.在插入 usb 驱动器时,触发DBT_DEVICEARRIVAL
。
case DBT_DEVICEARRIVAL:
if (b->dbcc_devicetype == DBT_DEVTYP_VOLUME)
{
PDEV_BROADCAST_HDR lpdbh = (PDEV_BROADCAST_HDR)lParam;
PDEV_BROADCAST_VOLUME vol = (PDEV_BROADCAST_VOLUME)lParam;
char drive = FirstDriveFromMask(vol->dbcv_unitmask);
}
The function FirstDriveFromMask() can detect first encountered partition from mask. function FirstDriveFromMask() 可以从掩码中检测到第一个遇到的分区。 How do I detect the other partitions from the usb drive.如何检测 usb 驱动器中的其他分区。
char FirstDriveFromMask(ULONG unitmask)// (usb has drive e:, f: )unitmask I receive is 48. Output is E
{
for (char i = 0; i < 26; ++i, unitmask >>= 1)
if (unitmask & 0x1)
return i + 'A';
return 0;
}
The following function could be helpful:以下 function 可能会有所帮助:
std::string DrivesFromMask(ULONG unitmask)
{
char i;
std::string drv = "";
for (i = 0; i < 26 && unitmask; ++i)
{
if (unitmask & 0x1)
{
drv += i + 'A';
}
unitmask = unitmask >> 1;
}
return drv;
}
And then read each drive letter in std::string
.然后读取std::string
中的每个驱动器号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.