⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wiadriver.cpp

📁 winddk src目录下的WDM源码压缩!
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                if (SUCCEEDED(hr))
                {
                    if ((guidItemCategory == WIA_CATEGORY_FINISHED_FILE) && !(lItemType & WiaItemTypeStorage))
                    {
                        // This is stream-based upload
                        IWiaMiniDrvTransferCallback *pTransferCallback = NULL;
                        hr = GetTransferCallback(pmdtc, &pTransferCallback);
                        if (SUCCEEDED(hr))
                        {
                            hr = UploadFromStream(lFlags, pWiasContext, guidItemCategory, pTransferCallback, plDevErrVal);
                            pTransferCallback->Release();
                            pTransferCallback = NULL;
                        }
                        else
                        {
                            WIAS_ERROR((g_hInst, "Could not get our IWiaMiniDrvTransferCallback for upload"));
                        }
                    }
                    else
                    {
                        hr = E_INVALIDARG;
                        WIAS_ERROR((g_hInst, "Cannot do Upload to selected item, hr = 0x%lx",hr));
                    }
                }
                else
                {
                    WIAS_ERROR((g_hInst, "Failed to get the WIA item type, hr = 0x%lx",hr));
                }
            }
            else
            {
                // This should not happen!
                hr = E_INVALIDARG;
            }
        }
        else
        {
            WIAS_ERROR((g_hInst, "Failed to read the WIA_IPA_ITEM_CATEGORY property, hr = 0x%lx",hr));
        }
    }
    else
    {
        hr = E_INVALIDARG;
        WIAS_ERROR((g_hInst, "Invalid parameters were passed, hr = 0x%lx",hr));
    }
    return hr;
}
HRESULT CWIADriver::drvInitItemProperties(__inout   BYTE *pWiasContext,
                                                    LONG lFlags,
                                          __out     LONG *plDevErrVal)
{
    HRESULT hr          = E_INVALIDARG;
    LONG    lItemFlags  = 0;
    if((pWiasContext)&&(plDevErrVal))
    {
        //
        // Initialize individual storage item properties using the CWIAStorage object
        //
        hr = wiasReadPropLong(pWiasContext,WIA_IPA_ITEM_FLAGS,&lItemFlags,NULL,TRUE);
        if(SUCCEEDED(hr))
        {
            if((lItemFlags & WiaItemTypeRoot))
            {
                //
                // Add any root item properties needed.  
                //

                hr = InitializeRootItemProperties(pWiasContext);
                if(FAILED(hr))
                {
                    WIAS_ERROR((g_hInst, "Failed to initialize generic WIA root item properties, hr = 0x%lx",hr));
                }
            }
            else
            {
                //
                // Add any non-root item properties needed.
                //
                GUID guidItemCategory = GUID_NULL;

                //
                // Use the WIA category setting to determine what type of property
                // set should be created for this WIA item.
                //
                if((lItemFlags & WiaItemTypeGenerated) == FALSE)
                {
                    //
                    // Item is not a generated item, assume that this was created by this WIA driver
                    // and the WIA_ITEM_CATEGORY setting can be read from the WIA_DRIVER_ITEM_CONTEXT
                    // structure stored with the WIA driver item.
                    //

                    WIA_DRIVER_ITEM_CONTEXT *pWiaDriverItemContext = NULL;
                    hr = wiasGetDriverItemPrivateContext(pWiasContext,(BYTE**)&pWiaDriverItemContext);
                    if(SUCCEEDED(hr) && (pWiaDriverItemContext))
                    {
                        guidItemCategory = pWiaDriverItemContext->guidItemCategory;
                    }
                    else
                    {
                        //
                        // This WIA item has no item context and will receive default item
                        // property initialization.  This allows applications to create child items
                        // for storing private data.
                        // NOTE: Data transfers on these types of items will probably not succeed since
                        //       the driver does not have a category to help classify the behavior of the
                        //       item.
                        //
                        hr = S_OK;
                    }
                }
                else
                {
                    //
                    // Read the parents WIA_ITEM_CATEGORY property setting to determine this new
                    // child item's category setting.
                    //

                    BYTE *pWiasParentContext = NULL;
                    hr = wiasGetAppItemParent(pWiasContext,&pWiasParentContext);
                    if(SUCCEEDED(hr))
                    {
                        hr = wiasReadPropGuid(pWiasParentContext,WIA_IPA_ITEM_CATEGORY,&guidItemCategory,NULL,TRUE);
                        if(FAILED(hr))
                        {
                            WIAS_TRACE((g_hInst,"The item does not have a category property setting. Assuming that it is unknown."));
                            //
                            // This WIA item has no item category property setting and will receive default item
                            // property initialization.  This allows applications to create child items
                            // for storing private data.
                            // NOTE: Data transfers on these types of items will probably not succeed since
                            //       the driver does not have a category to help classify the behavior of the
                            //       item.
                            //
                            hr = S_OK;
                        }
                    }
                    else
                    {
                        WIAS_ERROR((g_hInst, "Failed to obtain the WIA application item's parent, hr = 0x%lx",hr));
                    }
                }

                if(SUCCEEDED(hr))
                {
                    //
                    // Initialize the WIA item property set according to the category specified
                    //

                    if(guidItemCategory == WIA_CATEGORY_FLATBED)
                    {
                        //
                        // We do not support folder items to be created under the flatbed item:
                        //
                        LONG lItemFlags = 0;
                        hr = wiasReadPropLong(pWiasContext, WIA_IPA_ITEM_FLAGS, &lItemFlags, NULL, TRUE);

                        if ((SUCCEEDED(hr)) && (lItemFlags & WiaItemTypeFolder) && (lItemFlags & WiaItemTypeGenerated))
                        {
                            //
                            // This is a folder item to be created under the base flatbed item, deny the request:
                            //
                            hr = E_INVALIDARG;
                        }

                        if(SUCCEEDED(hr))
                        {
                            hr = InitializeWIAItemProperties(pWiasContext,g_hInst,IDB_FLATBED);
                        }
                        if(FAILED(hr))
                        {
                            WIAS_ERROR((g_hInst, "Failed to initialize the flatbed item's property set. hr = 0x%lx",hr));
                        }
                    }
                    else if(guidItemCategory == WIA_CATEGORY_FEEDER)
                    {
                        hr = InitializeWIAItemProperties(pWiasContext,g_hInst,IDB_FEEDER);
                        if(FAILED(hr))
                        {
                            WIAS_ERROR((g_hInst, "Failed to initialize the feeder item's property set. hr = 0x%lx",hr));
                        }
                    }
                    else if(guidItemCategory == WIA_CATEGORY_FILM)
                    {
                        hr = InitializeWIAItemProperties(pWiasContext,g_hInst,IDB_FILM);
                        if(FAILED(hr))
                        {
                            WIAS_ERROR((g_hInst, "Failed to initialize the film item's property set. hr = 0x%lx",hr));
                        }
                    }
                    else if((guidItemCategory == WIA_CATEGORY_FINISHED_FILE) || (WIA_CATEGORY_FOLDER == guidItemCategory))
                    {
                        hr = InitializeWIAStorageItemProperties(pWiasContext, FALSE, 
                            (BOOL)((WIA_CATEGORY_FOLDER == guidItemCategory) && (lItemFlags & WiaItemTypeFolder)));

                        if(FAILED(hr))
                        {
                            WIAS_ERROR((g_hInst, "Failed to initialize the storage item's property set. hr = 0x%lx",hr));
                        }
                    }
                    else
                    {
                        hr = S_OK;
                    }
                }
            }
        }
        else
        {
            WIAS_ERROR((g_hInst, "Failed to read WIA_IPA_ITEM_FLAGS property, hr = 0x%lx",hr));
        }
    }
    else
    {
        hr = E_INVALIDARG;
        WIAS_ERROR((g_hInst, "Invalid parameters were passed, hr = 0x%lx",hr));
    }

    if ((FAILED(hr)) && (plDevErrVal))
    {
        *plDevErrVal = (E_INVALIDARG == hr) ? WIA_ERROR_INVALID_COMMAND : WIA_ERROR_GENERAL_ERROR;
    }

    return hr;
}
HRESULT CWIADriver::drvValidateItemProperties(__inout   BYTE           *pWiasContext,
                                                        LONG           lFlags,
                                                        ULONG          nPropSpec,
                                              __in      const PROPSPEC *pPropSpec,
                                              __out     LONG           *plDevErrVal)
{
    HRESULT hr = E_INVALIDARG;
    if((pWiasContext)&&(pPropSpec)&&(plDevErrVal)&&(nPropSpec))
    {
        LONG lItemType = 0;
        hr = wiasGetItemType(pWiasContext,&lItemType);
        if(SUCCEEDED(hr))
        {
            if(lItemType & WiaItemTypeRoot)
            {
                //
                // Validate root item property settings, if needed.
                //

                hr = S_OK;
            }
            else
            {
                //
                // Validate child item property settings, if needed.
                //
                LONG                    lScanningSurfaceWidth   = 0;
                LONG                    lScanningSurfaceHeight  = 0;
                GUID                    guidItemCategory        = GUID_NULL;
                GUID                    guidFormat              = GUID_NULL;  
                WIA_PROPERTY_CONTEXT    PropertyContext         = {0};
                BOOL                    bUpdateFileExt          = FALSE; 

                //
                // Use the WIA item category to help classify and gather WIA item information
                // needed to validate the property set.
                //
                hr = wiasReadPropGuid(pWiasContext,WIA_IPA_ITEM_CATEGORY,&guidItemCategory,NULL,TRUE);
                if(SUCCEEDED(hr))
                {
                    BOOL bValidCategory = FALSE;
                    //
                    // Validate the selection area against the entire scanning surface of the device.
                    // The scanning surface may be different sizes depending on the type of WIA item.
                    // (ie. Flatbed glass platen sizes may be different to film scanning surfaces, and
                    // feeder sizes.)
                    //
                    if((guidItemCategory == WIA_CATEGORY_FLATBED)||(guidItemCategory == WIA_CATEGORY_FILM))
                    {
                        bValidCategory = TRUE;

                        //
                        // Flatbed items and Film items use the same WIA properties to describe their scanning
                        // surface.
                        //
                        hr = wiasReadPropLong(pWiasContext,WIA_IPS_MAX_HORIZONTAL_SIZE,&lScanningSurfaceWidth,NULL,TRUE);
                        if(SUCCEEDED(hr))
                        {
                            hr = wiasReadPropLong(pWiasContext,WIA_IPS_MAX_VERTICAL_SIZE,&lScanningSurfaceHeight,NULL,TRUE);
                            if(FAILED(hr))
                            {
                                WIAS_ERROR((g_hInst, "Failed to read WIA_IPS_MAX_VERTICAL_SIZE property, hr = 0x%lx",hr));
                            }
                        }
                        else
                        {
                            WIAS_ERROR((g_hInst, "Failed to read WIA_IPS_MAX_HORIZONTAL_SIZE property, hr = 0x%lx",hr));
                        }
                    }
                    else if(guidItemCategory == WIA_CATEGORY_FEEDER)
                    {
                        bValidCategory = TRUE;

                        //
                        // Feeder items use a different set of properties to describe the scanning surface.
                        //
                        hr = wiasReadPropLong(pWiasContext,WIA_IPS_MAX_HORIZONTAL_SIZE,&lScanningSurfaceWidth,NULL,TRUE);
                        if(SUCCEEDED(hr))
                        {
                            hr = wiasReadPropLong(pWiasContext,WIA_IPS_MAX_VERTICAL_SIZE,&lScanningSurfaceHeight,NULL,TRUE);
                            if(FAILED(hr))
                            {
                                WIAS_ERROR((g_hInst, "Failed to read WIA_IPS_MAX_VERTICAL_SIZE property, hr = 0x%lx",hr));
       

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -