將 WIA 屬性設定套用至硬體
當 WIA 應用程式起始資料傳輸時,WIA 服務可讓 WIA 迷你驅動程式有機會套用目前的 WIA 屬性設定,以及將任何裝置特定的設定套用至硬體。 WIA 服務接著會先呼叫 IWiaMiniDrv::d rvWriteItemProperties 方法,再呼叫 IWiaMiniDrv::d rvAcquireItemData 方法。 只有在 WIA 應用程式起始資料傳輸時,才會呼叫後者的方法。 WIA 迷你驅動程式應該使用 WIA 服務函式來讀取自己的驅動程式專案樹狀結構中的屬性。
實作 IWiaMiniDrv::d rvWriteItemProperties
WIA 服務會在用戶端要求資料傳輸之後呼叫 IWiaMiniDrv::d rvWriteItemProperties 方法。 WIA 服務會在呼叫 IWiaMiniDrv::d rvAcquireItemData之前呼叫此方法。 WIA 迷你驅動程式應該在從此方法傳回之前,先將它所需的任何設定認可到硬體。
呼叫此方法時,WIA 迷你驅動程式已認可為執行資料傳輸。 WIA 服務會失敗任何嘗試目前取得資料的應用程式,並出現WIA_ERROR_BUSY錯誤碼。
下列範例示範 IWiaMiniDrv::d rvWriteItemProperties 方法的實作:
HRESULT _stdcall CWIADevice::drvWriteItemProperties(
BYTE *pWiasContext,
LONG lFlags,
PMINIDRV_TRANSFER_CONTEXT pmdtc,
LONG *plDevErrVal)
{
//
// If the caller did not pass in the correct parameters,
// then fail the call with E_INVALIDARG.
//
if (!pWiasContext) {
return E_INVALIDARG;
}
if (!pmdtc) {
return E_INVALIDARG;
}
if (!plDevErrVal) {
return E_INVALIDARG;
}
HRESULT hr = S_OK;
*plDevErrVal = 0;
PROPVARIANT pv[2];
PROPSPEC ps[2] = {
{PRSPEC_PROPID, WIA_IPS_XRES},
{PRSPEC_PROPID, WIA_IPS_YRES}
};
//
// initialize propvariant structures
//
pv[0].vt = VT_I4; // X resolution is a LONG value
pv[1].vt = VT_I4; // Y resolution is a LONG value
//
// read 2 WIA item properties (X and Y resolution)
//
hr = wiasReadMultiple(pWiasContext, 2, ps, pv, NULL);
if (hr == S_OK) {
//
// write current X and Y resolution values, read from the
// the WIA property set, and write them to the device.
//
hr = SetMyDeviceXResolution(pv[0].lVal);
if(S_OK == hr) {
hr = SetMyDeviceYResolution(pv[1].lVal);
if(FAILED(hr)) {
//
// could not set Y resolution to device
//
}
} else {
//
// could not set X resolution to device
//
}
}
return hr;
}