【发布时间】:2011-09-29 16:23:57
【问题描述】:
为什么下面的代码总是报告 C:\ 尽管它报告了不同的设备名称
handle = FindFirstVolumeW(volName, sizeof(volName));
do{
wchar_t wVolName[MAX_PATH];
QString::fromWCharArray(volName).toWCharArray(wVolName);//make a copy of volName on wVolName
wVolName[wcslen(volName)-1] = L'\0';
wchar_t wDeviceName[MAX_PATH];
int charCount = 0;
charCount = QueryDosDeviceW(&wVolName[4], wDeviceName, ARRAYSIZE(wDeviceName));
qDebug() << QString::fromWCharArray(wVolName) << "Device: " << QString::fromWCharArray(wDeviceName);//print wVolName and wDeviceName
wchar_t driveName[MAX_PATH];
GetVolumePathName(wDeviceName, driveName, MAX_PATH);
CloseHandle(handle);
qDebug() << QString::fromWCharArray(driveName);
}while(FindNextVolume(handle, volName, sizeof(volName)));
FindVolumeClose(handle);
输出:
"\\?\Volume{5c77cc58-d5ab-11e0-a0ec-806d6172696f}" Device: "\Device\HarddiskVolume2"
"C:\"
"\\?\Volume{5c77cc59-d5ab-11e0-a0ec-806d6172696f}" Device: "\Device\HarddiskVolume3"
"C:\"
"\\?\Volume{5c77cc57-d5ab-11e0-a0ec-806d6172696f}" Device: "\Device\CdRom0"
"C:\"
"\\?\Volume{5c77cc56-d5ab-11e0-a0ec-806d6172696f}" Device: "\Device\Floppy0"
"C:\"
"\\?\Volume{8d974f2c-e9a1-11e0-b7da-0013d407432f}" Device: "\Device\Harddisk1\DP(1)0- 0+8"
"C:\"
为什么不报告D、E等..
编辑
以及如何获得分配给卷的驱动器号
【问题讨论】:
-
你检查GetVolumePathName成功了吗?它是否返回错误或成功代码?
-
因为
\Device\HarddiskVolume2可能会根据您当前的目录解析为C:\Device\HarddiskVolume2。 -
文档中其实是这样写的:必须指定一个有效的Win32命名空间路径。如果指定 NT 命名空间路径,例如“\DosDevices\H:”或“\Device\HardDiskVolume6”,则该函数返回当前卷的驱动器号,而不是该 NT 命名空间路径的驱动器号。
-
@Useless:是的,我检查过了。它返回 1。我只是省略了它以简要介绍代码。
-
@avakar: 那我需要做些什么来防止它以这种方式播放(前置`C:\`)?
标签: c++ winapi qt visual-c++