共用方式為


讀取應用程式的 WIA 專案屬性

當應用程式提出讀取 WIA 專案屬性的要求時,WIA 服務會呼叫 IWiaMiniDrv::d rvReadItemProperties 方法。

IWiaMiniDrv::d rvReadItemProperties方法應該執行下列工作:

  1. 判斷讀取的屬性是否需要執行時間更新。 若要判斷要讀取哪些 WIA 屬性,WIA 迷你驅動程式可以使用Microsoft Windows SDK檔) 中定義的 PROPSPEC 陣列 (。 建議 WIA 迷你驅動程式先決定專案類型,再處理 PROPSPEC 陣列。 這可減少在每個 IWiaMiniDrv::d rvReadItemProperties 呼叫上周遊陣列的需求。 如果此裝置的子專案上沒有執行時間屬性,則只會處理根專案屬性讀取要求。

  2. 使用 WIA 屬性的識別碼呼叫 wiasWriteMultiplewiasWritePropXxx 服務函式,以更新目前的值。 這會更新儲存在驅動程式專案中的 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;
}