繁体   English   中英

获取外部媒体类型

[英]getting external media type

我想找到一种在Windows上使用C ++的简单功能来检测光盘驱动器中媒体类型(例如DVD + R,DVD-R,DVD-RW,CD + R等)的方法。

该功能不需要管理员权限。

编辑

我实现了以下代码:

#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;

}

目前,我的问题是出现以下错误:E_IMAPI_RECORDER_REQUIRED,这表示“该请求需要选择当前的光盘刻录机”。

假设我至少有两个光驱,我之间如何区别?

有任何想法吗?

在Windows 2000及更高版本上,可以将IOCTL_CDROM_GET_CONFIGURATIONSCSI_GET_CONFIGURATION_REQUEST_TYPE_CURRENT标志一起使用,以查询光学设备的当前配置文件,该信息将告诉您已插入哪种类型的光盘(CD,DVD + -R / W,HDDVD,BluRay等)。 (如果有)。 在早期版本上,您将必须手动将SCSI MMC命令直接直接发送到设备以查询相同的信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM