更改 WIA 项树结构

WIA 微型驱动程序能够随时更改 WIA 项树结构。 当微型驱动程序对 WIA 项树进行更改时,微型驱动程序必须通知 WIA 服务。 然后,WIA 服务会通知所有连接的 WIA 应用程序。 收到通知后,WIA 应用程序必须枚举 WIA 项树以确定任何更改的结果。

微型驱动程序使用 WIA 服务实用工具函数 wiasQueueEvent 将树结构中的更改传达给 WIA 服务。 WIA 微型驱动程序只能将 IWiaMiniDrv::d rvGetCapabilities 中报告的事件排队。 有关报告 WIA 事件的详细信息,请参阅 事件报告

IWiaMiniDrv::d rvDeleteItem 实现的说明

WIA 应用程序调用 IWiaItem::D eleteItem 方法时,WIA 服务调用 IWiaMiniDrv::d rvDeleteItem 方法, (Microsoft Windows SDK文档) 删除 WIA 项。

WIA 服务在调用此方法之前验证以下内容:

  • 该项不是根项。

  • 该项没有子项。

  • 项的访问权限允许删除。

由于 WIA 服务会验证这些条件,因此 WIA 驱动程序也不需要这样做。

下面的代码示例演示 IWiaMiniDrv::d rvDeleteItem 的实现:

HRESULT _stdcall CWIADevice::drvDeleteItem(BYTE *pWiasContext,
                                           LONG lFlags,
                                           LONG *plDevErrVal)
{
    //
    // If the caller did not pass in the correct parameters,
    // then fail the call with E_INVALIDARG.
    //

    if ((!pWiasContext) || (!plDevErrVal))
    {
        return E_INVALIDARG;
    }

    *plDevErrVal = 0;

    HRESULT hr = S_OK;

    //
    // Two pieces of information are needed to queue an event:
    // 1. Full item name
    // 2. Device ID (passed in from drvInitializeWia,
    //    or read from the ROOT item's property set)
    //

    BSTR bstrFullItemName = NULL;
    hr = wiasReadPropStr(pWiasContext,
                         WIA_IPA_FULL_ITEM_NAME,
                         &bstrFullItemName,NULL,TRUE);
    if (hr == S_OK)
    {
        hr = HARDWARE_DELETE_DATA_FOR_ITEM();
        if (hr == S_OK)
        {
            //
            // Use m_bstrDeviceID cached from the
            // drvInitializeWia method call.
            //

            hr = wiasQueueEvent(m_bstrDeviceID,
                                &WIA_EVENT_ITEM_DELETED,
                                bstrFullItemName);
        }

        //
        // Free item's full item name, read above.
        //

        if (bstrFullItemName)
        {
            SysFreeString(bstrFullItemName);
            bstrFullItemName = NULL;
        }
    }

    //
    // Returning S_OK will instruct the WIA service to remove the WIA
    // item from the item tree. The WIA minidriver should only remove
    // any associated data corresponding to the target item.
    //

    return hr;
}