Condividi tramite


Scrittura di proprietà WIA da un driver

Un minidriver WIA può aggiornare uno dei valori correnti delle relative proprietà WIA e valori validi usando le funzioni del servizio WIA seguenti:

wiasWriteMultiple
Scrivere tutti i tipi di proprietà WIA. Si tratta di una funzione generale che consente a un driver WIA di scrivere qualsiasi proprietà esistente in un elemento WIA, incluse le proprietà personalizzate. Può essere usato per scrivere in più proprietà per chiamata.

wiasWritePropStr
Scrivere proprietà WIA che sono stringhe (tipo VT_BSTR).

wiasWritePropLong
Scrivere proprietà WIA che sono numeri interi a quattro byte (tipo VT_I4).

wiasWritePropFloat
Scrivere proprietà WIA che sono numeri reali a quattro byte (tipo VT_R4).

wiasWritePropGuid
Scrivere proprietà WIA che sono GUID (tipo VT_CLSID).

wiasWritePropBin
Scrivere proprietà WIA che sono stringhe di byte senza segno (tipo VT_VECTOR | VT_UI1).

wiasGetChangedValueLong
Ottenere le informazioni modificate correnti per le proprietà WIA che sono numeri interi a quattro byte (tipo VT_I4).

wiasGetChangedValueFloat
Ottenere le informazioni aggiornate sulle proprietà WIA che sono numeri reali a quattro byte (tipo VT_R4).

wiasGetChangedValueGuid
Ottenere le informazioni modificate correnti per le proprietà WIA che sono GUID (tipo VT_CLSID).

wiasGetChangedValueStr
Ottenere le informazioni modificate correnti per le proprietà WIA che sono stringhe (tipo VT_BSTR).

wiasCreatePropContext
Creare un contesto di proprietà WIA, che viene usato nelle funzioni del servizio wiasGetChangedValueLong, wiasGetChangedValueFloat, wiasGetChangedValueGuid e wiasGetChangedValueStr.

wiasFreePropContext
Liberare la memoria del contesto allocata creata da wiasCreatePropContext.

Implementazione di IWiaMiniDrv::d rvValidateItemProperties

Il metodo IWiaMiniDrv::d rvValidateItemProperties viene chiamato quando vengono apportate modifiche alle proprietà WIA di un elemento. Il minidriver WIA non deve solo verificare che i valori siano validi, ma deve aggiornare tutti i valori validi che cambiano.

Se una proprietà WIA non è valida e l'applicazione non la scrive, il valore non valido e i valori dipendenti devono essere modificati in valori validi oppure la convalida non riesce perché l'applicazione imposta la proprietà su un valore non valido.

L'esempio seguente illustra un'implementazione del metodo 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;
}