Condividi tramite


Metodo IDiscMaster2::get_Item (imapi2.h)

Recupera l'identificatore univoco del dispositivo disco specificato.

Sintassi

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

Parametri

[in] index

Indice in base zero del dispositivo il cui identificatore univoco si vuole recuperare.

Il valore dell'indice può cambiare durante l'attività PNP quando i dispositivi vengono aggiunti o rimossi dal computer o tra sessioni di avvio.

[out] value

Stringa contenente l'identificatore univoco del dispositivo disco associato all'indice specificato.

Valore restituito

S_OK viene restituito in caso di esito positivo, ma altri codici di esito positivo possono essere restituiti in seguito all'implementazione. I codici di errore seguenti vengono comunemente restituiti in caso di errore dell'operazione, ma non rappresentano gli unici valori di errore possibili:

Codice restituito Descrizione
E_INVALIDARG
Uno o più argomenti non sono validi.

Valore: 0x80070057

E_POINTER
Puntatore non valido.

Valore: 0x80004003

E_OUTOFMEMORY
Impossibile allocare la memoria necessaria.

Valore: 0x8007000E

Commenti

Per enumerare tutti gli identificatori, chiamare il metodo IDiscMaster2::get__NewEnum .

L'esempio seguente illustra come enumerare nuovamente le unità ottiche per tenere conto con precisione delle unità aggiunte o rimosse dopo la creazione iniziale dell'oggetto IDiscMaster2 . Questa operazione viene eseguita tramite i metodi IDiscMaster2::get_Item e 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;

Requisiti

   
Client minimo supportato Windows Vista, Windows XP con SP2 [solo app desktop]
Server minimo supportato Windows Server 2003 [solo app desktop]
Piattaforma di destinazione Windows
Intestazione imapi2.h

Vedi anche

IDiscMaster2

IDiscMaster2::get_Count

IDiscRecorder2::InitializeDiscRecorder