Share via


IDiscMaster2::get_Item メソッド (imapi2.h)

指定したディスク デバイスの一意識別子を取得します。

構文

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

パラメーター

[in] index

一意の識別子を取得するデバイスの 0 から始まるインデックス。

インデックス値は、デバイスがコンピューターに追加または削除されたとき、またはブート セッション間で PNP アクティビティ中に変更される可能性があります。

[out] value

指定したインデックスに関連付けられているディスク デバイスの一意識別子を含む文字列。

戻り値

S_OKは成功時に返されますが、実装の結果として他の成功コードが返される場合があります。 次のエラー コードは通常、操作の失敗時に返されますが、考えられる唯一のエラー値を表すわけではありません。

リターン コード 説明
E_INVALIDARG
1 つ以上の引数が無効です。

値: 0x80070057

E_POINTER
ポインターが無効です。

値: 0x80004003

E_OUTOFMEMORY
必要なメモリを割り当てませんでした。

値: 0x8007000E

解説

すべての識別子を列挙するには、 IDiscMaster2::get__NewEnum メソッドを呼び出します。

次の例では、 IDiscMaster2 オブジェクトの最初の作成後に追加または削除されたドライブを正確に考慮するために、光学式ドライブを再列挙する方法を示します。 これは、 IDiscMaster2::get_Item メソッドと IDiscMaster2::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