Exemplo de código para inicializar propriedades do dispositivo
Durante a chamada IWiaMiniDrv::d rvInitItemProperties para o item Raiz, o minidriver deve inicializar as seguintes propriedades wia que descrevem o dispositivo:
O exemplo de código a seguir mostra como inicializar WIA_DPS_SERVICE_ID usando os métodos OpenPropertyStore e ReadDeviceProperty para ler PKEY_PNPX_ServiceId. O mesmo método geral pode ser usado para inicializar cada uma das propriedades do dispositivo.
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;
}