WIA 微型驱动程序可使用以下 WIA 服务函数来更新其 WIA 属性的任何当前值和有效值:
wiasWriteMultiple
写入所有 WIA 属性类型。 这是一个常规函数,允许 WIA 驱动程序写入 WIA 项目上存在的任何属性,包括自定义属性。 它可以用于在每次调用时写入多个属性。
wiasWritePropStr
写入字符串(类型 VT_BSTR)的 WIA 属性。
wiasWritePropLong
写入四字节整数(类型 VT_I4)的 WIA 属性。
wiasWritePropFloat
写入四字节实数(类型 VT_R4)的 WIA 属性。
wiasWritePropGuid
写入 GUID(类型 VT_CLSID)的 WIA 属性。
wiasWritePropBin
写入无符号字节字符串(类型 VT_VECTOR | VT_UI1)的 WIA 属性。
wiasGetChangedValueLong
获取四字节整数(类型 VT_I4)WIA 属性的当前更改信息。
wiasGetChangedValueFloat
获取四字节实数(类型 VT_R4)WIA 属性的当前更改信息。
wiasGetChangedValueGuid
获取 GUID(类型 VT_CLSID)WIA 属性的当前更改信息。
wiasGetChangedValueStr
获取字符串(类型 VT_BSTR)WIA 属性的当前更改信息。
wiasCreatePropContext
创建 WIA 属性上下文,该上下文用于 wiasGetChangedValueLong、wiasGetChangedValueFloat、wiasGetChangedValueGuid 和 wiasGetChangedValueStr 服务函数。
wiasFreePropContext
释放由 wiasCreatePropContext 创建的已分配上下文内存。
实现 IWiaMiniDrv::drvValidateItemProperties
IWiaMiniDrv::drvValidateItemProperties 方法会在项目的 WIA 属性发生更改时被调用。 WIA 微型驱动程序不仅要检查数值是否有效,还必须更新任何发生变化的有效数值。
如果 WIA 属性无效,并且应用程序没有向其写入内容,则必须将无效值和任何从属值更改为有效值,否则将导致验证失败(因为应用程序将该属性设置为无效值)。
以下示例演示了 IWiaMiniDrv::drvValidateItemProperties 方法的实现:
HRESULT _stdcall CWIADevice::drvValidateItemProperties(
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;
}
HRESULT hr = S_OK;
LONG lItemType = 0;
WIA_PROPERTY_CONTEXT Context;
*plDevErrVal = 0;
//
// create a WIA property context, to gain access to
// the WIA application's intended settings.
//
hr = wiasCreatePropContext(nPropSpec,
(PROPSPEC*)pPropSpec,
0,
NULL,
&Context);
if(S_OK == hr) {
//
// get the current item type to help determine what property set to validate
//
hr = wiasGetItemType(pWiasContext, &lItemType);
if (S_OK == hr) {
if (lItemType & WiaItemTypeRoot) {
//
// validate root item properties here
//
} else {
//
// validate item properties here
//
WIAS_CHANGED_VALUE_INFO cviDataType;
memset(&cviDataType,0,sizeof(cviDataType));
//
// check to see if the application was updating
// the WIA_IPA_DATATYPE property
//
hr = wiasGetChangedValueLong(pWiasContext,pContext,FALSE,WIA_IPA_DATATYPE,&cviDataType);
if(S_OK == hr) {
if (cviDataType.bChanged) {
//
// This value was changed, and needs to be checked
//
// cviDataType.Current.lVal is the current application setting.
//
} else {
//
// Nothing has been changed, so leave this property alone.
// Let the WIA service function wiasValidateItemProperties
// do the rest of the work for you.
//
}
}
}
//
// free the property context
//
wiasFreePropContext(&Context);
}
//
// call WIA service helper when you have finished updating dependent values
//
if(S_OK == hr) {
//
// call WIA service helper to validate other properties
//
hr = wiasValidateItemProperties(pWiasContext, nPropSpec, pPropSpec);
}
}
return hr;
}