디바이스 속성 읽기
애플리케이션은 디바이스의 IWiaPropertyStorage 인터페이스를 사용하여 디바이스 속성을 읽고 씁니다. IWiaPropertyStorage 는 COM(구성 요소 개체 모델) 인터페이스 IPropertyStorage의 모든 메서드를 상속합니다.
디바이스 속성에는 디바이스의 기능 및 설정을 설명하는 디바이스에 대한 정보가 포함됩니다. 이러한 속성 목록은 디바이스 속성을 참조하세요.
IWiaPropertyStorage를 사용하여 읽는 디바이스 속성 중에는 WIA(Windows 이미지 획득) 디바이스를 만드는 데 사용되는 디바이스 ID가 있습니다. 자세한 내용은 IWiaDevMgr::CreateDevice (또는 IWiaDevMgr2::CreateDevice)를 참조하세요.
다음 예제에서는 디바이스 속성 배열에서 디바이스 ID, 디바이스 이름 및 디바이스 설명을 읽고 이러한 속성을 콘솔에 출력합니다.
HRESULT ReadSomeWiaProperties( IWiaPropertyStorage *pWiaPropertyStorage )
{
//
// Validate arguments
//
if (NULL == pWiaPropertyStorage)
{
return E_INVALIDARG;
}
//
// Declare PROPSPECs and PROPVARIANTs, and initialize them to zero.
//
PROPSPEC PropSpec[3] = {0};
PROPVARIANT PropVar[3] = {0};
//
// How many properties are you querying for?
//
const ULONG c_nPropertyCount = sizeof(PropSpec)/sizeof(PropSpec[0]);
//
// Define which properties you want to read:
// Device ID. This is what you would use to create
// the device.
//
PropSpec[0].ulKind = PRSPEC_PROPID;
PropSpec[0].propid = WIA_DIP_DEV_ID;
//
// Device Name
//
PropSpec[1].ulKind = PRSPEC_PROPID;
PropSpec[1].propid = WIA_DIP_DEV_NAME;
//
// Device description
//
PropSpec[2].ulKind = PRSPEC_PROPID;
PropSpec[2].propid = WIA_DIP_DEV_DESC;
//
// Ask for the property values
//
HRESULT hr = pWiaPropertyStorage->ReadMultiple( c_nPropertyCount, PropSpec, PropVar );
if (SUCCEEDED(hr))
{
//
// IWiaPropertyStorage::ReadMultiple will return S_FALSE if some
// properties could not be read, so you have to check the return
// types for each requested item.
//
//
// Check the return type for the device ID
//
if (VT_BSTR == PropVar[0].vt)
{
//
// Do something with the device ID
//
_tprintf( TEXT("WIA_DIP_DEV_ID: %ws\n"), PropVar[0].bstrVal );
}
//
// Check the return type for the device name
//
if (VT_BSTR == PropVar[1].vt)
{
//
// Do something with the device name
//
_tprintf( TEXT("WIA_DIP_DEV_NAME: %ws\n"), PropVar[1].bstrVal );
}
//
// Check the return type for the device description
//
if (VT_BSTR == PropVar[2].vt)
{
//
// Do something with the device description
//
_tprintf( TEXT("WIA_DIP_DEV_DESC: %ws\n"), PropVar[2].bstrVal );
}
//
// Free the returned PROPVARIANTs
//
FreePropVariantArray( c_nPropertyCount, PropVar );
}
//
// Return the result of reading the properties
//
return hr;
}
이 예제에서 애플리케이션은 속성 정보를 보유하도록 PROPVARIANT 배열(각각 PropSpec 및 PropVar)을 설정합니다. 이러한 배열은 IWiaPropertyStorage 포인터 pIWiaPropStg의 IPropertyStorage::ReadMultiple 메서드 호출에서 매개 변수로 전달됩니다. PropSpec 배열의 각 요소에는 디바이스 속성의 형식과 이름이 포함됩니다. 반환 시 PropVar 의 각 요소에는 PropSpec 배열의 해당 요소가 나타내는 디바이스 속성의 값이 포함됩니다.
그런 다음 애플리케이션은 IWiaPropertyStorage 포인터 pWiaPropertyStorage의 IPropertyStorage::ReadMultiple 속성을 호출하여 속성 정보를 검색합니다.
디바이스 속성을 읽고 설정하는 데 사용되는 기술은 항목 속성의 경우와 동일하며, 유일한 차이점은 적절한 메서드를 호출하는 WIA 항목의 형식입니다. 항목 속성 목록은 항목 속성을 참조하세요.
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기