Compartir a través de


Escritura de propiedades de WIA mediante un controlador

Un minicontrolador WIA puede actualizar cualquiera de los valores actuales de sus propiedades WIA y valores válidos mediante las siguientes funciones de servicio WIA:

wiasWriteMultiple
Escribe todos los tipos de propiedades WIA. Se trata de una función general que permite que un controlador WIA escriba cualquier propiedad existente en un elemento WIA, incluidas las propiedades personalizadas. Se puede usar para escribir en varias propiedades por llamada.

wiasWritePropStr
Escribe propiedades WIA que son cadenas (tipo VT_BSTR).

wiasWritePropLong
Escribe propiedades WIA que son enteros de cuatro bytes (tipo VT_I4).

wiasWritePropFloat
Escribe propiedades WIA que son números reales de cuatro bytes (tipo VT_R4).

wiasWritePropGuid
Escribe propiedades WIA que son GUID (tipo VT_CLSID).

wiasWritePropBin
Escribe propiedades WIA que son cadenas de bytes sin signo (tipo VT_VECTOR | VT_UI1).

wiasGetChangedValueLong
Obtiene la información modificada actual de las propiedades de WIA que son enteros de cuatro bytes (tipo VT_I4).

wiasGetChangedValueFloat
Obtiene la información modificada actual de las propiedades de WIA que son números reales de cuatro bytes (tipo VT_R4).

wiasGetChangedValueGuid
Obtiene la información modificada actual de las propiedades de WIA que son GUID (tipo VT_CLSID).

wiasGetChangedValueStr
Obtiene la información modificada actual de las propiedades WIA que son cadenas (tipo VT_BSTR).

wiasCreatePropContext
Crea un contexto de propiedad WIA, que se usa en las funciones de servicio wiasGetChangedValueLong, wiasGetChangedValueFloat, wiasGetChangedValueGuid y wiasGetChangedValueStr.

wiasFreePropContext
Libera la memoria de contexto asignada creada por wiasCreatePropContext.

Implementación de IWiaMiniDrv::d rvValidateItemProperties

Se llama al método IWiaMiniDrv::d rvValidateItemProperties cuando se realizan cambios en las propiedades WIA de un elemento. El minicontrolador WIA no solo debe comprobar que los valores son válidos, sino que debe actualizar los valores válidos que cambian.

Si una propiedad WIA no es válida y la aplicación no está escribiendo en ella, el valor no válido y los valores dependientes deben cambiarse a valores válidos o, de lo contrario, se producirá un error en la validación (porque la aplicación establece la propiedad en un valor no válido).

En el siguiente código de ejemplo se muestra la implementación del método 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;
}