Bagikan melalui


Mengubah struktur pohon item WIA

Minidriver WIA memiliki kemampuan untuk mengubah struktur pohon item WIA kapan saja. Ketika minidriver membuat perubahan pada pohon item WIA, minidriver harus memberi tahu layanan WIA. Layanan WIA kemudian memberi tahu semua aplikasi WIA yang terhubung. Setelah pemberitahuan diterima, aplikasi WIA harus menghitung pohon item WIA untuk menentukan hasil perubahan apa pun.

Minidriver menggunakan fungsi utilitas layanan WIA, wiasQueueEvent, untuk mengkomunikasikan perubahan struktur pohon pada layanan WIA. Minidriver WIA hanya dapat mengantre peristiwa yang dilaporkan di IWiaMiniDrv::d rvGetCapabilities. Untuk informasi selengkapnya tentang melaporkan peristiwa WIA, lihat Pelaporan Peristiwa.

Penjelasan implementasi IWiaMiniDrv::d rvDeleteItem

Layanan WIA memanggil metode IWiaMiniDrv::d rvDeleteItem ketika aplikasi WIA memanggil metode IWiaItem::D eleteItem (dijelaskan dalam dokumentasi Microsoft Windows SDK) untuk menghapus item WIA.

Layanan WIA memverifikasi hal berikut sebelum memanggil metode ini:

  • Item ini bukan item akar.

  • Item tidak memiliki turunan.

  • Hak akses item memungkinkan penghapusan.

Karena layanan WIA memverifikasi kriteria ini, tidak perlu bagi pengemudi WIA untuk melakukannya juga.

Contoh kode berikut menunjukkan implementasi 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;
}