IDiscMaster2::get_Item 메서드(imapi2.h)

지정된 디스크 디바이스의 고유 식별자를 검색합니다.

구문

HRESULT get_Item(
  [in]  LONG index,
  [out] BSTR *value
);

매개 변수

[in] index

검색하려는 고유 식별자를 가진 디바이스의 인덱스(0부터 시작)입니다.

컴퓨터 또는 부팅 세션에서 디바이스를 추가하거나 제거할 때 PNP 작업 중에 인덱스 값이 변경될 수 있습니다.

[out] value

지정된 인덱스와 연결된 디스크 디바이스의 고유 식별자를 포함하는 문자열입니다.

반환 값

S_OK 성공에 따라 반환되지만 구현의 결과로 다른 성공 코드가 반환될 수 있습니다. 다음 오류 코드는 일반적으로 작업 실패 시 반환되지만 가능한 오류 값만 나타내지 않습니다.

반환 코드 설명
E_INVALIDARG
하나 이상의 인수가 잘못되었습니다.

값: 0x80070057

E_POINTER
포인터가 잘못되었습니다.

값: 0x80004003

E_OUTOFMEMORY
필요한 메모리를 할당하지 못했습니다.

값: 0x8007000E

설명

모든 식별자를 열거하려면 IDiscMaster2::get__NewEnum 메서드를 호출합니다.

다음 샘플에서는 IDiscMaster2 개체를 처음 만든 후 추가되거나 제거된 드라이브를 정확하게 설명하기 위해 광학 드라이브를 다시 열거하는 방법을 보여 줍니다. 이 작업은 IDiscMaster2::get_ItemIDiscMaster2::get_Count 메서드를 통해 수행됩니다.

#include <windows.h>
#include <tchar.h>
#include <imapi2.h>
#include <objbase.h>
#include <stdio.h>

#pragma comment(lib, "ole32.lib")
#pragma comment(lib, "user32.lib")

int __cdecl _tmain(int argc, TCHAR* argv[])   
{   
    BSTR           bstrDeviceName;   
    HRESULT        hr = S_OK;   
    BOOL           bComInitialised;       
    IDiscMaster2*  discMaster;   
    UINT           iCounter = 0; 
    LONG           lValue = 0; 

    bComInitialised = SUCCEEDED(CoInitializeEx(0, COINIT_MULTITHREADED));

    // Create an object of IDiscMaster2  
    if (SUCCEEDED(hr)){
        CoCreateInstance(
            CLSID_MsftDiscMaster2,
            NULL, CLSCTX_ALL,
            IID_PPV_ARGS(&discMaster)
        );   

        if(FAILED(hr)){
            _tprintf(TEXT("\nUnsuccessful in creating an instance of CLSID_MsftDiscMaster2.\n\nError returned: 0x%x\n"), hr);
            return 0;
        }
    }
    //
    // Loop twice and get the optical drives attached to the system,
    // first time just get the current configuration and second time 
    // prompt the user to change the configuration and then get the 
    // altered configuration.   
    //
    do{
        // Get the number of drives 
        if (SUCCEEDED(hr)){
            hr = discMaster->get_Count(&lValue);
            if (SUCCEEDED(hr)){
                _tprintf(TEXT("\nTotal number of drives = %d\n"), lValue);
            }
        }

        // Print all the optical drives attached to the system 
        if (SUCCEEDED(hr)){
            for(LONG iCount = 0; iCount < lValue; iCount++) {
                hr = discMaster->get_Item(iCount, &bstrDeviceName);
                _tprintf(TEXT("\nUnique identifier of the disc device associated with index %d is: %s\n"), iCount, bstrDeviceName);
            }            
        }

        // Prompt the user to unhook or add drives
        if (iCounter < 1){
            MessageBox(NULL,TEXT("Please un-hook or add drives and hit OK"), TEXT("Manual Action"), MB_OK);
            _tprintf(TEXT("\nGetting the altered configuration ... \n"));
        }
        iCounter++;
    }while(iCounter < 2);

    discMaster->Release();
    CoUninitialize();   
    bComInitialised = FALSE;   

    return 0;

요구 사항

   
지원되는 최소 클라이언트 Windows Vista, WINDOWS XP SP2 [데스크톱 앱만 해당]
지원되는 최소 서버 Windows Server 2003 [데스크톱 앱만 해당]
대상 플랫폼 Windows
헤더 imapi2.h

참고 항목

IDiscMaster2

IDiscMaster2::get_Count

IDiscRecorder2::InitializeDiscRecorder