如何以编程方式区分插入的 dvd 或 mini dvd 磁盘?
How to programmatically differentiate between dvd or mini dvd disk inserted?
我需要获取插入的 DVD 磁盘的容量。
DeviceIoControl 函数调用 IOCTL_DISK_GET_DRIVE_GEOMETRY_EX 参数写入 4128768 字节作为 DVD 的大小,这显然是错误的结果。代码取自 https://docs.microsoft.com/en-us/windows/win32/devio/calling-deviceiocontrol.
另一种解决方案是通过 ckMMC 库的设备接口确定磁盘读取或写入速度,并根据其类型确定 return 大小。但这不是可靠的解决方案,因为不同 CD/DVD 驱动器的速度可能会有所不同。
也许,我遗漏了一些关于 DeviceIoControl 用法的东西,它可以 return 我得到正确的结果,或者有更好的方法来计算 DVD 磁盘的容量。
在 DVD_LAYER_DESCRIPTOR 中有一个字段 DiskSize
,我正在寻找它。
首先,我们应该以正确的权限打开驱动器。
HANDLE drive = CreateFileW(devicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, nullptr);
注意 devicePath
,它应该在 Win32 Device Namespace. After getting drive handle, with the help of DeviceIoControl get DVD_LAYER_DESCRIPTOR
结构中。
DWORD unused;
std::array<char, 22> buffer;
DVD_READ_STRUCTURE dvdReadStruct;
dvdReadStruct.Format = DvdPhysicalDescriptor;
DeviceIoControl(drive, IOCTL_DVD_READ_STRUCTURE, &dvdReadStruct, sizeof(dvdReadStruct),
buffer.data(), buffer.size(), &unused, nullptr))
DVD_LAYER_DESCRIPTOR layerDescription = *reinterpret_cast<DVD_LAYER_DESCRIPTOR *>(
reinterpret_cast<DVD_DESCRIPTOR_HEADER *>(buffer.data())->Data);
CloseHandle(drive);
dvdReadStruct.Format
决定哪个结构将被写入buffer
。例如,如果您将设置 DvdManufacturerDescriptor
,函数将 DVD_MANUFACTURER_DESCRIPTOR 写入缓冲区。
我需要获取插入的 DVD 磁盘的容量。
DeviceIoControl 函数调用 IOCTL_DISK_GET_DRIVE_GEOMETRY_EX 参数写入 4128768 字节作为 DVD 的大小,这显然是错误的结果。代码取自 https://docs.microsoft.com/en-us/windows/win32/devio/calling-deviceiocontrol.
另一种解决方案是通过 ckMMC 库的设备接口确定磁盘读取或写入速度,并根据其类型确定 return 大小。但这不是可靠的解决方案,因为不同 CD/DVD 驱动器的速度可能会有所不同。
也许,我遗漏了一些关于 DeviceIoControl 用法的东西,它可以 return 我得到正确的结果,或者有更好的方法来计算 DVD 磁盘的容量。
在 DVD_LAYER_DESCRIPTOR 中有一个字段 DiskSize
,我正在寻找它。
首先,我们应该以正确的权限打开驱动器。
HANDLE drive = CreateFileW(devicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, nullptr);
注意 devicePath
,它应该在 Win32 Device Namespace. After getting drive handle, with the help of DeviceIoControl get DVD_LAYER_DESCRIPTOR
结构中。
DWORD unused;
std::array<char, 22> buffer;
DVD_READ_STRUCTURE dvdReadStruct;
dvdReadStruct.Format = DvdPhysicalDescriptor;
DeviceIoControl(drive, IOCTL_DVD_READ_STRUCTURE, &dvdReadStruct, sizeof(dvdReadStruct),
buffer.data(), buffer.size(), &unused, nullptr))
DVD_LAYER_DESCRIPTOR layerDescription = *reinterpret_cast<DVD_LAYER_DESCRIPTOR *>(
reinterpret_cast<DVD_DESCRIPTOR_HEADER *>(buffer.data())->Data);
CloseHandle(drive);
dvdReadStruct.Format
决定哪个结构将被写入buffer
。例如,如果您将设置 DvdManufacturerDescriptor
,函数将 DVD_MANUFACTURER_DESCRIPTOR 写入缓冲区。