通过驱动程序写入 WIA 属性
WIA 微型驱动程序可以通过使用以下 WIA 服务函数来更新其 WIA 属性和有效值的任何当前值:
wiasWriteMultiple
写入所有 WIA 属性类型。 这是一个常规功能,它允许 WIA 驱动程序写入 WIA 项(包括自定义属性)中的任何现有属性。 它可用于写入每个调用的多个属性。
wiasWritePropStr
将作为字符串 (类型 VT_BSTR) 的 WIA 属性写入。
wiasWritePropLong
(类型 VT_I4) 写入 WIA 属性,这些属性为四字节整数。
wiasWritePropFloat
将 (类型 VT_R4) 的 WIA 属性写入为四字节实数。
wiasWritePropGuid
(类型 VT_CLSID) 写入作为 Guid 的 WIA 属性。
wiasWritePropBin
将作为无符号字节字符串的 WIA 属性写入 (类型 VT_VECTOR |VT_UI1) 。
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::d rvValidateItemProperties
当对项的 WIA 属性进行更改时,将调用 IWiaMiniDrv::D rvvalidateitemproperties 方法。 WIA 微型驱动程序不仅应检查值是否有效,而且必须更新任何更改的有效值。
如果 WIA 属性无效,并且应用程序没有写入它,则必须将无效值和任何依赖值更改为有效值,否则验证 (将失败,因为应用程序会将属性设置为无效的值) 。
下面的示例演示 IWiaMiniDrv::D rvvalidateitemproperties 方法的实现:
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;
}