디바이스 속성을 초기화하기 위한 코드 예제
루트 항목에 대한 IWiaMiniDrv::d rvInitItemProperties 호출 중에 미니 드라이버는 디바이스를 설명하는 다음 WIA 속성을 초기화해야 합니다.
다음 코드 예제에서는 OpenPropertyStore 및 ReadDeviceProperty 메서드를 사용하여 PKEY_PNPX_ServiceId 읽어 WIA_DPS_SERVICE_ID 초기화하는 방법을 보여 줍니다. 동일한 일반 메서드를 사용하여 각 디바이스 속성을 초기화할 수 있습니다.
HRESULT hr = S_OK;
IPropertyStore *pPropertyStore = NULL;
BSTR bstrPropertyValue = NULL;
//
// Open the current Property Store and keep it opened until all needed properties are read
//
if (SUCCEEDED(hr))
{
hr = OpenPropertyStore(&pPropertyStore);
if (FAILED(hr))
{
WIAS_ERROR((g_hInst, "Failed to open the Property Store for the current Function Instance, hr = 0x%08X", hr));
}
}
//
// Initialize WIA_DPS_SERVICE_ID
//
if (SUCCEEDED(hr))
{
hr = ReadDeviceProperty(pPropertyStore, &PKEY_PNPX_ServiceId, &bstrPropertyValue);
if (FAILED(hr))
{
WIAS_ERROR((g_hInst, "Failed to read the PKEY_PNPX_ServiceId device property, hr = 0x%08X", hr));
}
if ((SUCCEEDED(hr)) && (bstrPropertyValue))
{
WIAS_TRACE((g_hInst, "Service id: %ws", (LPWSTR)bstrPropertyValue));
hr = AddProperty(WIA_DPS_SERVICE_ID, WIA_DPS_SERVICE_ID_STR, RN, bstrPropertyValue);
if (FAILED(hr))
{
WIAS_ERROR((g_hInst, "Failed to add WIA_DPS_SERVICE_ID property to the property manager, hr = 0x%08X", hr));
}
}
if (bstrPropertyValue)
{
SysFreeString(bstrPropertyValue);
bstrPropertyValue = NULL;
}
}
//
// Repeat the same procedure for WIA_DPS_DEVICE_ID, WIA_DPS_GLOBAL_IDENTITY, and WIA_DPS_FIRMWARE_VERSION
//
//
// Close the Property Store
//
if (pPropertyStore)
{
pPropertyStore->Release();
pPropertyStore = NULL;
}