通过应用程序读取 WIA 项属性
当应用程序发出读取 WIA 项属性的请求时,WIA 服务会调用 IWiaMiniDrv::d rvReadItemProperties 方法。
IWiaMiniDrv::d rvReadItemProperties 方法应执行以下任务:
确定正在读取的属性是否需要运行时更新。 若要确定正在读取哪些 WIA 属性,WIA 微型驱动程序可以使用Microsoft Windows SDK文档) 中定义的 PROPSPEC 数组 (。 建议 WIA 微型驱动程序在处理 PROPSPEC 数组之前确定项类型。 这减少了在每次 IWiaMiniDrv::d rvReadItemProperties 调用上遍历数组的需要。 如果此设备的子项上没有运行时属性,则只会处理根项属性读取请求。
通过使用 WIA 属性的 ID 调用 wiasWriteMultiple 或 wiasWritePropXxx 服务函数来更新当前值。 这会更新存储在驱动程序项中的 WIA 属性集,WIA 服务将新值返回给应用程序。
如果 WIA 微型驱动程序在此函数中不对 WIA 属性执行任何运行时调整,WIA 服务会自动将当前 WIA 属性值返回给应用程序。 此函数应仅用于需要硬件特定检查的属性(如设备时钟)或 WIA 属性,例如文档送纸器状态。
实现 IWiaMiniDrv::d rvReadItemProperties
当应用程序尝试读取 WIA 项的属性时,将调用 IWiaMiniDrv::d rvReadItemProperties 方法。 WIA 服务首先通过调用此方法通知驱动程序。 WIA 驱动程序应验证正在读取的属性是否正确。 这是访问需要设备状态 (的属性(例如 WIA_DPS_DOCUMENT_HANDLING_STATUS)或 WIA_DPA_DEVICE_TIME (如果设备支持时钟) )的硬件的良好位置。
请务必注意,WIA 驱动程序应仅在极少数情况下与硬件通信。 在此调用中与硬件通信过多的 WIA 驱动程序将显示缓慢和缓慢。
以下示例演示 IWiaMiniDrv::d rvReadItemProperties 方法的实现:
HRESULT _stdcall CWIADevice::drvReadItemProperties(
BYTE *pWiasContext,
LONG lFlags,
ULONG nPropSpec,
const PROPSPEC *pPropSpec,
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 (!plDevErrVal) {
return E_INVALIDARG;
}
if (!pPropSpec) {
return E_INVALIDARG;
}
*plDevErrVal = 0;
LONG lWIAItemType = 0;
HRESULT hr = wiasGetItemType(pWiasContext,&lWIAItemType);
if(S_OK == hr) {
//
// perform custom operations depending on the type of
// WIA item that was passed to drvReadItemProperties
//
if(lWIAItemType & WiaItemTypeRoot) {
//
// If the WIA_DPA_CONNECT_STATUS property ID is in the PROPSPEC
// array, then read the latest "Connect Status".
// If it is NOT then do nothing. (skip access to the hardware)
//
// NOTE: only read properties contained in the PROPSPEC array
// from the hardware that need device updates.
// If the property in PROPSPEC does not need to be read
// from the hardware, or updated, do nothing. The WIA service
// will supply the caller with the current value in the
// the WIA property set.
//
BOOL bReadLatestConnectStatus = FALSE;
//
// traverse the WIA PROPSPEC array, looking for known WIA
// properties that require run-time updates, or needs to be
// updated with hardware access.
//
for(ULONG ulIndex = 0; ulIndex < nPropSpec; ulIndex++) {
//
// look for WIA property IDs that really need hardware
// access, or run-time adjusting.
//
if(pPropSpec[ulIndex].propid == WIA_DPA_CONNECT_STATUS) {
bReadLatestConnectStatus = TRUE;
}
}
//
// The item passed in is a ROOT item
//
if(bReadLatestConnectStatus) {
//
// WIA_DPA_CONNECT_STATUS should be updated from the
// hardware
//
LONG lConnectStatus = HARDWARE_READ_ConnectStatus();
//
// update WIA_DPA_CONNECT_STATUS property value using
// wiasWritePropLong (). The pWiasContext passed in
// already represents the current item to be written to.
//
hr = wiasWritePropLong(pWiasContext,WIA_DPA_CONNECT_STATUS,lConnectStatus);
if(S_OK == hr) {
//
// The WIA_DPA_CONNECT_STATUS property was successfully updated
//
} else {
//
// wiasWritePropLong() failed to write the WIA
// property. The WIA_DPA_CONNECT_STATUS
// property was NOT updated
//
}
}
} else {
//
// The item passed in is any other child item
//
}
} else {
//
// wiasGetItemType() failed to get the current item type
//
}
return hr;
}