HRESULT InitializeWIAItemProperties()

in wia/wiadriverex/usd/wiahelpers.cpp [485:1052]


HRESULT InitializeWIAItemProperties(
    _In_    BYTE        *pWiasContext,
    _In_    HINSTANCE   hInstance,
            UINT        uiResourceID)
{
    // WARNING: No checks for failed CBasicDynamicArray::Append() calls.
    // For robustness, error handling should be added.

    HRESULT hr = E_INVALIDARG;
    BOOL bRootFilm = FALSE;

    if((pWiasContext)&&(hInstance))
    {
        //
        // Reset the feeder image transfer count:
        //
        WIA_DRIVER_ITEM_CONTEXT *pWiaDriverItemContext = NULL;
        hr = wiasGetDriverItemPrivateContext(pWiasContext, (BYTE**)&pWiaDriverItemContext);
        if ((SUCCEEDED(hr)) && (!pWiaDriverItemContext))
        {
            hr = E_POINTER;
        }
        if (SUCCEEDED(hr))
        {
            pWiaDriverItemContext->ulFeederTransferCount = 0;
        }

        if (SUCCEEDED(hr))
        {
            CWIAPropertyManager PropertyManager;

            LONG lXPosition         = 0;
            LONG lYPosition         = 0;
            LONG lXExtent           = 0;
            LONG lYExtent           = 0;
            LONG lPixWidth          = 0;
            LONG lPixHeight         = 0;
            LONG lXResolution       = 75;  // Our sample images are 75 dpi
            LONG lYResolution       = 75;  // Our sample images are 75 dpi
            LONG lHorizontalSize    = 0;
            LONG lVerticalSize      = 0;
            LONG lMinHorizontalSize = 1; //0.001"
            LONG lMinVerticalSize   = 1; //0.001"
            LONG lItemType          = 0;

            HBITMAP hBitmap = static_cast<HBITMAP>(LoadImage(hInstance, MAKEINTRESOURCE(uiResourceID), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION));

            if (hBitmap)
            {
                Bitmap *pBitmap = Bitmap::FromHBITMAP(hBitmap, NULL);

                if (pBitmap)
                {
                    lXExtent        = (LONG)pBitmap->GetWidth();
                    lYExtent        = (LONG)pBitmap->GetHeight();
                    lPixWidth       = lXExtent;
                    lPixHeight      = lYExtent;
                    lHorizontalSize = ConvertTo1000thsOfAnInch(lXExtent, lXResolution);
                    lVerticalSize   = ConvertTo1000thsOfAnInch(lYExtent, lYResolution);

                    SAFE_DELETE (pBitmap);
                }

                DeleteObject(hBitmap);
                hBitmap = NULL;
            }

            //
            // Set coordinates for fixed frames
            //
            if (IDB_FILM == uiResourceID)
            {
                ULONG   ulFrame      = NO_FIXED_FRAME;
                BSTR    bstrItemName = NULL;
                //  Get the item name
                hr = wiasReadPropStr(pWiasContext, WIA_IPA_ITEM_NAME, &bstrItemName, NULL, TRUE);

                if (S_OK == hr)
                {
                    if (!lstrcmp(bstrItemName, L"Frame1"))
                    {
                        ulFrame = 0;
                    }
                    else if (!lstrcmp(bstrItemName, L"Frame2"))
                    {
                        ulFrame = 1;
                    }
                    else if (!lstrcmp(bstrItemName, L"Frame3"))
                    {
                        ulFrame = 2;
                    }
                    else if (!lstrcmp(bstrItemName, L"Frame4"))
                    {
                        ulFrame = 3;
                    }
                    else
                    {
                        bRootFilm = TRUE;
                    }

                    if (ulFrame != NO_FIXED_FRAME)
                    {
                        lXPosition = g_FilmFrames[ulFrame].XPOS;
                        lYPosition = g_FilmFrames[ulFrame].YPOS;
                        lXExtent   = g_FilmFrames[ulFrame].XEXTENT;
                        lYExtent   = g_FilmFrames[ulFrame].YEXTENT;
                    }

                    SysFreeString(bstrItemName);
                    bstrItemName = NULL;
                }
            }

            hr = wiasGetItemType(pWiasContext,&lItemType);
            if(SUCCEEDED(hr))
            {
                if(lItemType & WiaItemTypeGenerated)
                {
                    WIAS_TRACE((g_hInst,"WIA item was created by application."));
                }
            }
            else
            {
                WIAS_ERROR((g_hInst, "Failed to get the WIA item type, hr = 0x%lx",hr));
            }

            //
            // Add all common item properties first
            //

            if((lXExtent)&&(lYExtent)&&(lXResolution)&&(lYResolution)&&(lHorizontalSize)&&(lVerticalSize))
            {
                LONG lAccessRights = WIA_ITEM_READ;
                hr = PropertyManager.AddProperty(WIA_IPA_ACCESS_RIGHTS ,WIA_IPA_ACCESS_RIGHTS_STR ,RF, lAccessRights, lAccessRights);

                if(SUCCEEDED(hr))
                {
                    LONG lOpticalXResolution = lXResolution;
                    hr = PropertyManager.AddProperty(WIA_IPS_OPTICAL_XRES ,WIA_IPS_OPTICAL_XRES_STR ,RN,lOpticalXResolution);
                }

                if(SUCCEEDED(hr))
                {
                    LONG lOpticalYResolution = lYResolution;
                    hr = PropertyManager.AddProperty(WIA_IPS_OPTICAL_YRES ,WIA_IPS_OPTICAL_YRES_STR ,RN,lOpticalYResolution);
                }

                if(SUCCEEDED(hr))
                {
                    CBasicDynamicArray<LONG> lPreviewArray;
                    lPreviewArray.Append(WIA_FINAL_SCAN);
                    lPreviewArray.Append(WIA_PREVIEW_SCAN);
                    hr = PropertyManager.AddProperty(WIA_IPS_PREVIEW ,WIA_IPS_PREVIEW_STR ,RWLC,lPreviewArray[0],lPreviewArray[0],&lPreviewArray);
                }

                if(SUCCEEDED(hr))
                {
                    LONG lShowPreviewControl = WIA_SHOW_PREVIEW_CONTROL;
                    hr = PropertyManager.AddProperty(WIA_IPS_SHOW_PREVIEW_CONTROL ,WIA_IPS_SHOW_PREVIEW_CONTROL_STR ,RN,lShowPreviewControl);
                }

                if(SUCCEEDED(hr))
                {
                    //
                    // Support creation of child items underneath the base flatbed item:
                    //
                    BOOL bChildItemCreation = FALSE;

                    if(uiResourceID == IDB_FLATBED)
                    {
                        LONG lItemFlags = 0;
                        hr = wiasReadPropLong(pWiasContext, WIA_IPA_ITEM_FLAGS, &lItemFlags, NULL, TRUE);
                        if ((S_OK == hr) && (lItemFlags & WiaItemTypeFolder))
                        {
                            bChildItemCreation = TRUE;
                        }
                    }

                    hr = PropertyManager.AddProperty(WIA_IPS_SUPPORTS_CHILD_ITEM_CREATION, WIA_IPS_SUPPORTS_CHILD_ITEM_CREATION_STR, RN, bChildItemCreation);
                }

                if((uiResourceID == IDB_FLATBED) || (uiResourceID == IDB_FILM))
                {
                    if(SUCCEEDED(hr))
                    {
                        hr = PropertyManager.AddProperty(WIA_IPS_MAX_HORIZONTAL_SIZE ,WIA_IPS_MAX_HORIZONTAL_SIZE_STR ,RN,lHorizontalSize);
                    }

                    if(SUCCEEDED(hr))
                    {
                        hr = PropertyManager.AddProperty(WIA_IPS_MAX_VERTICAL_SIZE ,WIA_IPS_MAX_VERTICAL_SIZE_STR ,RN,lVerticalSize);
                    }

                    if(SUCCEEDED(hr))
                    {
                        hr = PropertyManager.AddProperty(WIA_IPS_MIN_HORIZONTAL_SIZE ,WIA_IPS_MIN_HORIZONTAL_SIZE_STR ,RN,lMinHorizontalSize);
                    }

                    if(SUCCEEDED(hr))
                    {
                        hr = PropertyManager.AddProperty(WIA_IPS_MIN_VERTICAL_SIZE ,WIA_IPS_MIN_VERTICAL_SIZE_STR ,RN,lMinVerticalSize);
                    }

                    if(SUCCEEDED(hr))
                    {
                        LONG lSegmentation = (IDB_FLATBED == uiResourceID) ? WIA_USE_SEGMENTATION_FILTER : WIA_DONT_USE_SEGMENTATION_FILTER;
                        hr = PropertyManager.AddProperty(WIA_IPS_SEGMENTATION ,WIA_IPS_SEGMENTATION_STR ,RN, lSegmentation);
                    }

                    if (SUCCEEDED(hr) && (IDB_FILM == uiResourceID))
                    {
                        if (bRootFilm)
                        {
                            CBasicDynamicArray<LONG> lFilmScanModeArray;
                            lFilmScanModeArray.Append(WIA_FILM_COLOR_SLIDE);
                            hr = PropertyManager.AddProperty(WIA_IPS_FILM_SCAN_MODE, WIA_IPS_FILM_SCAN_MODE_STR, RWL, lFilmScanModeArray[0], lFilmScanModeArray[0], &lFilmScanModeArray);
                        }
                    }
                }
                else if(uiResourceID == IDB_FEEDER)
                {
                    if(SUCCEEDED(hr))
                    {
                        hr = PropertyManager.AddProperty(WIA_IPS_MAX_HORIZONTAL_SIZE ,WIA_IPS_MAX_HORIZONTAL_SIZE_STR ,RN,lHorizontalSize);
                    }

                    if(SUCCEEDED(hr))
                    {
                        hr = PropertyManager.AddProperty(WIA_IPS_MAX_VERTICAL_SIZE ,WIA_IPS_MAX_VERTICAL_SIZE_STR ,RN,lVerticalSize);
                    }

                    if(SUCCEEDED(hr))
                    {
                        hr = PropertyManager.AddProperty(WIA_IPS_MIN_HORIZONTAL_SIZE ,WIA_IPS_MIN_HORIZONTAL_SIZE_STR ,RN,lMinHorizontalSize);
                    }

                    if(SUCCEEDED(hr))
                    {
                        hr = PropertyManager.AddProperty(WIA_IPS_MIN_VERTICAL_SIZE ,WIA_IPS_MIN_VERTICAL_SIZE_STR ,RN,lMinVerticalSize);
                    }

                    if(SUCCEEDED(hr))
                    {
                        LONG lSheetFeederRegistration = LEFT_JUSTIFIED;
                        hr = PropertyManager.AddProperty(WIA_IPS_SHEET_FEEDER_REGISTRATION ,WIA_IPS_SHEET_FEEDER_REGISTRATION_STR ,RN,lSheetFeederRegistration);
                    }

                    if(SUCCEEDED(hr))
                    {
                        //
                        // Just basic duplex mode supported (no single back side scan):
                        //
                        LONG lDocumentHandlingSelect            = FRONT_ONLY;
                        LONG lDocumentHandlingSelectValidValues = FRONT_ONLY |DUPLEX;
                        hr = PropertyManager.AddProperty(WIA_IPS_DOCUMENT_HANDLING_SELECT ,WIA_IPS_DOCUMENT_HANDLING_SELECT_STR ,RWF,lDocumentHandlingSelect,lDocumentHandlingSelectValidValues);
                    }

                    if(SUCCEEDED(hr))
                    {
                        LONG lMaxPages            = 100;
                        LONG lDefaultPagesSetting = 1;
                        LONG lPages               = 1;
                        hr = PropertyManager.AddProperty(WIA_IPS_PAGES ,WIA_IPS_PAGES_STR ,RWR,lDefaultPagesSetting,lDefaultPagesSetting,0,lMaxPages,lPages);
                    }

                    //
                    // For the Feeder item implement support for WIA_IPS_PAGE_SIZE (just AUTO supported for now,
                    // in a real case standard and possibly document sizes would have to be added here):
                    //
                    if (SUCCEEDED(hr))
                    {
                        LONG lAutoPageSize = WIA_PAGE_AUTO;
                        hr = PropertyManager.AddProperty(WIA_IPS_PAGE_SIZE, WIA_IPS_PAGE_SIZE_STR, RN, lAutoPageSize);

                        CBasicDynamicArray<LONG> lPageSizeArray;
                        lPageSizeArray.Append(WIA_PAGE_AUTO);
                        hr = PropertyManager.AddProperty(WIA_IPS_PAGE_SIZE, WIA_IPS_PAGE_SIZE_STR, RWL, lPageSizeArray[0], lPageSizeArray[0], &lPageSizeArray);
                    }

                    //
                    // WIA_IPS_PAGE_WIDTH and WIA_IPS_PAGE_HEIGHT are required for feeder item
                    //
                    if (SUCCEEDED(hr)) {
                        hr = PropertyManager.AddProperty(WIA_IPS_PAGE_WIDTH, WIA_IPS_PAGE_WIDTH_STR, RN, lHorizontalSize);
                    }

                    if (SUCCEEDED(hr)) {
                        hr = PropertyManager.AddProperty(WIA_IPS_PAGE_HEIGHT, WIA_IPS_PAGE_HEIGHT_STR, RN, lVerticalSize);
                    }

                    if (SUCCEEDED(hr)) {
                        CBasicDynamicArray<LONG> lOrientationArray;
                        lOrientationArray.Append(PORTRAIT);
                        lOrientationArray.Append(LANSCAPE);
                        lOrientationArray.Append(ROT180);
                        lOrientationArray.Append(ROT270);
                        hr = PropertyManager.AddProperty(WIA_IPS_ORIENTATION, WIA_IPS_ORIENTATION_STR, RWL, lOrientationArray[0], lOrientationArray[0], &lOrientationArray);
                    }
                }

                if(SUCCEEDED(hr))
                {
                    LONG lCurrentIntent             = WIA_INTENT_NONE;
                    LONG lCurrentIntentValidValues  = WIA_INTENT_IMAGE_TYPE_COLOR | WIA_INTENT_MINIMIZE_SIZE | WIA_INTENT_MAXIMIZE_QUALITY;
                    hr = PropertyManager.AddProperty(WIA_IPS_CUR_INTENT ,WIA_IPS_CUR_INTENT_STR ,RWF,lCurrentIntent,lCurrentIntentValidValues);
                }

                if(SUCCEEDED(hr))
                {
                    GUID guidItemCategory = WIA_CATEGORY_FLATBED;
                    switch(uiResourceID)
                    {
                    case IDB_FLATBED:
                        guidItemCategory = WIA_CATEGORY_FLATBED;
                        break;
                    case IDB_FEEDER:
                        guidItemCategory = WIA_CATEGORY_FEEDER;
                        break;
                    case IDB_FILM:
                        guidItemCategory = WIA_CATEGORY_FILM;
                        break;
                    default:
                        guidItemCategory = GUID_NULL;
                        break;
                    }

                    hr = PropertyManager.AddProperty(WIA_IPA_ITEM_CATEGORY,WIA_IPA_ITEM_CATEGORY_STR,RN,guidItemCategory);
                }

                if(SUCCEEDED(hr))
                {
                    CBasicDynamicArray<LONG> lXResolutionArray;
                    lXResolutionArray.Append(lXResolution);
                    hr = PropertyManager.AddProperty(WIA_IPS_XRES ,WIA_IPS_XRES_STR ,RWLC,lXResolutionArray[0],lXResolutionArray[0],&lXResolutionArray);
                }

                if(SUCCEEDED(hr))
                {
                    CBasicDynamicArray<LONG> lYResolutionArray;
                    lYResolutionArray.Append(lYResolution);
                    hr = PropertyManager.AddProperty(WIA_IPS_YRES ,WIA_IPS_YRES_STR ,RWLC,lYResolutionArray[0],lYResolutionArray[0],&lYResolutionArray);
                }

                if(SUCCEEDED(hr))
                {
                    hr = PropertyManager.AddProperty(WIA_IPS_XPOS, WIA_IPS_XPOS_STR, RWRC, lXPosition, lXPosition, 0, lPixWidth - 1, 1);
                }

                if(SUCCEEDED(hr))
                {
                    hr = PropertyManager.AddProperty(WIA_IPS_YPOS, WIA_IPS_YPOS_STR, RWRC, lYPosition, lYPosition, 0, lPixHeight -1, 1);
                }

                if(SUCCEEDED(hr))
                {
                    hr = PropertyManager.AddProperty(WIA_IPS_XEXTENT ,WIA_IPS_XEXTENT_STR ,RWRC, lXExtent, lXExtent, 1, lPixWidth - lXPosition, 1);
                }

                if(SUCCEEDED(hr))
                {
                    hr = PropertyManager.AddProperty(WIA_IPS_YEXTENT ,WIA_IPS_YEXTENT_STR ,RWRC, lYExtent, lYExtent, 1, lPixHeight - lYPosition, 1);
                }

                if(SUCCEEDED(hr))
                {
                    CBasicDynamicArray<LONG> lRotationArray;
                    lRotationArray.Append(PORTRAIT);
                    lRotationArray.Append(LANSCAPE);
                    lRotationArray.Append(ROT180);
                    lRotationArray.Append(ROT270);

                    hr = PropertyManager.AddProperty(WIA_IPS_ROTATION ,WIA_IPS_ROTATION_STR ,RWLC,lRotationArray[0],lRotationArray[0],&lRotationArray);
                }

                if(SUCCEEDED(hr))
                {
                    hr = PropertyManager.AddProperty(WIA_IPS_DESKEW_X ,WIA_IPS_DESKEW_X_STR ,RWRC,0,0,0,lXExtent,1);
                }

                if(SUCCEEDED(hr))
                {
                    hr = PropertyManager.AddProperty(WIA_IPS_DESKEW_Y ,WIA_IPS_DESKEW_Y_STR ,RWRC,0,0,0,lYExtent,1);
                }

                if(SUCCEEDED(hr))
                {
                    LONG lBrightness = 0;
                    hr = PropertyManager.AddProperty(WIA_IPS_BRIGHTNESS,WIA_IPS_BRIGHTNESS_STR,RWRC,lBrightness,lBrightness,-1000,1000,1);
                }

                if(SUCCEEDED(hr))
                {
                    LONG lContrast = 0;
                    hr = PropertyManager.AddProperty(WIA_IPS_CONTRAST ,WIA_IPS_CONTRAST_STR ,RWRC,lContrast,lContrast,-1000,1000,1);
                }

                if(SUCCEEDED(hr))
                {
                    LONG lErrorHandler             = ERROR_HANDLING_NONE;
                    LONG lErrorHandlerValidValues  = ERROR_HANDLING_WARMING_UP | ERROR_HANDLING_COVER_OPEN | ERROR_HANDLING_PRIVATE_ERROR | ERROR_HANDLING_UNHANDLED_STATUS | ERROR_HANDLING_UNHANDLED_ERROR;

                    hr = PropertyManager.AddProperty(MY_WIA_ERROR_HANDLING_PROP ,MY_WIA_ERROR_HANDLING_PROP_STR ,RWF,lErrorHandler,lErrorHandlerValidValues);
                }

                if(SUCCEEDED(hr))
                {
                    CBasicDynamicArray<LONG> lTestFilterArray;
                    lTestFilterArray.Append(0);
                    lTestFilterArray.Append(1);

                    hr = PropertyManager.AddProperty(MY_TEST_FILTER_PROP ,MY_TEST_FILTER_PROP_STR ,RWLC,lTestFilterArray[0],lTestFilterArray[0],&lTestFilterArray);
                }

                if(SUCCEEDED(hr))
                {
                    LONG lItemSize = 0;
                    hr = PropertyManager.AddProperty(WIA_IPA_ITEM_SIZE ,WIA_IPA_ITEM_SIZE_STR ,RN,lItemSize);
                }

                if(SUCCEEDED(hr))
                {
                    // TBD: This property is assuming that the source image is color.  Should be changed to be
                    //      more dynamic.
                    CBasicDynamicArray<LONG> lDataTypeArray;
                    lDataTypeArray.Append(WIA_DATA_COLOR);
                    hr = PropertyManager.AddProperty(WIA_IPA_DATATYPE ,WIA_IPA_DATATYPE_STR ,RWL,lDataTypeArray[0],lDataTypeArray[0],&lDataTypeArray);
                }

                if(SUCCEEDED(hr))
                {
                    // TBD: This property is assuming that the source image is 24-bit color.  Should be changed to be
                    //      more dynamic.
                    CBasicDynamicArray<LONG> lBitDepthArray;
                    lBitDepthArray.Append(24);
                    hr = PropertyManager.AddProperty(WIA_IPA_DEPTH ,WIA_IPA_DEPTH_STR ,RWLC,lBitDepthArray[0],lBitDepthArray[0],&lBitDepthArray);
                }

                if(SUCCEEDED(hr))
                {
                    GUID guidPreferredFormat = WiaImgFmt_BMP;
                    hr = PropertyManager.AddProperty(WIA_IPA_PREFERRED_FORMAT ,WIA_IPA_PREFERRED_FORMAT_STR ,RN,guidPreferredFormat);
                }

                if(SUCCEEDED(hr))
                {
                    CBasicDynamicArray<GUID> guidFormatArray;
                    guidFormatArray.Append(WiaImgFmt_BMP);
                    guidFormatArray.Append(WiaImgFmt_RAW);
                    hr = PropertyManager.AddProperty(WIA_IPA_FORMAT ,WIA_IPA_FORMAT_STR ,RWL,guidFormatArray[0],guidFormatArray[0],&guidFormatArray);
                }

                if(SUCCEEDED(hr))
                {
                    CBasicDynamicArray<LONG> lCompressionArray;
                    lCompressionArray.Append(WIA_COMPRESSION_NONE);
                    hr = PropertyManager.AddProperty(WIA_IPA_COMPRESSION ,WIA_IPA_COMPRESSION_STR ,RWL, lCompressionArray[0], lCompressionArray[0], &lCompressionArray);
                }

                if(SUCCEEDED(hr))
                {
                    CBasicDynamicArray<LONG> lTymedArray;
                    lTymedArray.Append(TYMED_FILE);
                    hr = PropertyManager.AddProperty(WIA_IPA_TYMED ,WIA_IPA_TYMED_STR ,RWL,lTymedArray[0],lTymedArray[0],&lTymedArray);
                }

                if(SUCCEEDED(hr))
                {
                    // TBD: This property is assuming that the source image is 24-bit color and has 3 channels.  Should be changed to be
                    //      more dynamic.
                    LONG lChannelsPerPixel = 3;
                    hr = PropertyManager.AddProperty(WIA_IPA_CHANNELS_PER_PIXEL ,WIA_IPA_CHANNELS_PER_PIXEL_STR ,RN,lChannelsPerPixel);
                }

                if(SUCCEEDED(hr))
                {
                    // TBD: This property is assuming that the source image is 24-bit color and has 8 bits per channel.  Should be changed to be
                    //      more dynamic.
                    LONG lBitsPerChannel = 8;
                    hr = PropertyManager.AddProperty(WIA_IPA_BITS_PER_CHANNEL ,WIA_IPA_BITS_PER_CHANNEL_STR ,RN,lBitsPerChannel);
                }

                if(SUCCEEDED(hr))
                {
                    //
                    // According with the limited type of input image data we use in this sample
                    // we'll initialize this property for 24-bit color / 3 channels RGB image data.
                    // (see also above the initialization of WIA_IPA_CHANNELS_PER_PIXEL and WIA_IPA_BITS_PER_CHANNEL)
                    // A real solution may need however to consider more than just this single format:
                    //
                    BYTE bBitsPerChannel[] = { 8, 8, 8 };
                    hr = PropertyManager.AddProperty(WIA_IPA_RAW_BITS_PER_CHANNEL, WIA_IPA_RAW_BITS_PER_CHANNEL_STR, RN, &bBitsPerChannel[0], 3);
                }

                if(SUCCEEDED(hr))
                {
                    //
                    // WIA_IPS_PHOTOMETRIC_INTERP is needed for the Raw transfer format:
                    // (It shall have WIA_PROP_LIST (with single valid value) | WIA_PROP_RW
                    //
                    CBasicDynamicArray<LONG> lPhotometricInterpArray;
                    lPhotometricInterpArray.Append(WIA_PHOTO_WHITE_1);
                    hr = PropertyManager.AddProperty(WIA_IPS_PHOTOMETRIC_INTERP, WIA_IPS_PHOTOMETRIC_INTERP_STR, RWL,
                        lPhotometricInterpArray[0], lPhotometricInterpArray[0], &lPhotometricInterpArray);
                }

                if(SUCCEEDED(hr))
                {
                    LONG lPlanar = WIA_PACKED_PIXEL;
                    hr = PropertyManager.AddProperty(WIA_IPA_PLANAR ,WIA_IPA_PLANAR_STR ,RN,lPlanar);
                }

                if(SUCCEEDED(hr))
                {
                    // TBD: A small buffer size was used here to allow slower transfers with more progress.  Real
                    //      drivers should use a higher value to increase performance.
                    LONG lBufferSize = DEFAULT_BUFFER_SIZE;
                    hr = PropertyManager.AddProperty(WIA_IPA_BUFFER_SIZE ,WIA_IPA_BUFFER_SIZE_STR ,RN,lBufferSize);
                }

                if(SUCCEEDED(hr))
                {
                    BSTR bstrFileExtension = SysAllocString(L"BMP");
                    if(bstrFileExtension)
                    {
                        hr = PropertyManager.AddProperty(WIA_IPA_FILENAME_EXTENSION ,WIA_IPA_FILENAME_EXTENSION_STR ,RN,bstrFileExtension);

                        SysFreeString(bstrFileExtension);
                        bstrFileExtension = NULL;
                    }
                    else
                    {
                        hr = E_OUTOFMEMORY;
                        WIAS_ERROR((g_hInst, "Could not allocate the file name extension property value, hr = 0x%lx.",hr));
                    }
                }

                /* Optional property
                if(SUCCEEDED(hr))
                {
                GUID guidStreamCompatID = GUID_NULL;
                hr = PropertyManager.AddProperty(WIA_IPA_PROP_STREAM_COMPAT_ID,WIA_IPA_PROP_STREAM_COMPAT_ID_STR,RN,guidStreamCompatID);
                }*/

                if(SUCCEEDED(hr))
                {
                    hr = PropertyManager.SetItemProperties(pWiasContext);
                    if(FAILED(hr))
                    {
                        WIAS_ERROR((g_hInst, "CWIAPropertyManager::SetItemProperties failed to set WIA flatbed item properties, hr = 0x%lx",hr));
                    }
                }
            }
            else
            {
                WIAS_ERROR((g_hInst, "Failed to obtain valid information from flatbed bitmap file resource to build a WIA property set"));
            }
        }
        else
        {
            WIAS_ERROR((g_hInst, "Failed to obtain driver item context data"));
        }
    }
    else
    {
        WIAS_ERROR((g_hInst, "Invalid parameters were passed"));
    }
    return hr;
}