[英]getting external media type
i would like to find a way detecting the type of the media in my optical drive (eg DVD+R, DVD-R, DVD-RW, CD+R, etc.) using a simple function in C++ on windows. 我想找到一种在Windows上使用C ++的简单功能来检测光盘驱动器中媒体类型(例如DVD + R,DVD-R,DVD-RW,CD + R等)的方法。
The function should not require Admin privilege. 该功能不需要管理员权限。
EDIT 编辑
I implemented the following code: 我实现了以下代码:
#include <windows.h>
#include <winioctl.h>
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <imapi2.h>
#include <imapi2fs.h>
#include <imapi2error.h>
#include <imapi2fserror.h>
int main(int argc, char *argv[])
{
IDiscFormat2Data* discFormatData = NULL;
HRESULT hr;
CoInitialize ( NULL );
hr = CoCreateInstance( __uuidof(MsftDiscFormat2Data),
NULL,
CLSCTX_ALL,
__uuidof(IDiscFormat2Data),
(void**)&discFormatData);
if ( SUCCEEDED(hr) )
{
IMAPI_MEDIA_PHYSICAL_TYPE mediaType = IMAPI_MEDIA_TYPE_UNKNOWN;
hr = discFormatData->get_CurrentPhysicalMediaType(&mediaType);
if ( SUCCEEDED(hr) )
{
std::cout << "MediaPhysicalType: " << mediaType << std::endl;
}
else
{
std::stringstream str;
str << "get_CurrentPhysicalMediaType() failed with the error: 0x";
str << std::hex << hr << ".";
std::cout << str.str() << std::endl;
}
// Release the interface.
// Tell the COM object that we're done with it.
discFormatData->Release();
}
else
{
std::stringstream str;
str << "CoCreateInstance() failed with the error: 0x" << std::hex << hr;
std::cout << str.str() << std::endl;
}
cin.get();
return 0;
}
at the moment my problem is that i get the following error: E_IMAPI_RECORDER_REQUIRED which means "The request requires a current disc recorder to be selected." 目前,我的问题是出现以下错误:E_IMAPI_RECORDER_REQUIRED,这表示“该请求需要选择当前的光盘刻录机”。
Assuming i have at least two optical drivers, how can i differ between them? 假设我至少有两个光驱,我之间如何区别?
Any ideas? 有任何想法吗?
On Windows 2000 and later, you can use IOCTL_CDROM_GET_CONFIGURATION
with the SCSI_GET_CONFIGURATION_REQUEST_TYPE_CURRENT
flag to query an optical device for its current profile, which will tell you which type of disc (CD, DVD+-R/W, HDDVD, BluRay, etc) has been inserted, if any. 在Windows 2000及更高版本上,可以将
IOCTL_CDROM_GET_CONFIGURATION
与SCSI_GET_CONFIGURATION_REQUEST_TYPE_CURRENT
标志一起使用,以查询光学设备的当前配置文件,该信息将告诉您已插入哪种类型的光盘(CD,DVD + -R / W,HDDVD,BluRay等)。 (如果有)。 On earlier versions, you will have to manually send SCSI MMC commands directly to the device to query the same info. 在早期版本上,您将必须手动将SCSI MMC命令直接直接发送到设备以查询相同的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.