IDiscMaster2::get_Item 方法 (imapi2.h)
擷取指定之光碟裝置的唯一識別碼。
語法
HRESULT get_Item(
[in] LONG index,
[out] BSTR *value
);
參數
[in] index
要擷取其唯一識別碼之裝置之以零起始的索引。
當裝置從電腦新增或移除,或跨開機會話新增或移除裝置時,索引值可能會變更。
[out] value
字串,包含與指定索引相關聯之光碟裝置的唯一識別碼。
傳回值
S_OK會在成功時傳回,但可能會因為實作而傳回其他成功碼。 下列錯誤碼通常會在作業失敗時傳回,但不代表唯一可能的錯誤值:
傳回碼 | 描述 |
---|---|
|
一或多個引數無效。
值:0x80070057 |
|
指標無效。
值:0x80004003 |
|
無法配置所需的記憶體。
值: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 |