Question

I'm new to WIA. I somehow managed to get a device listing, select my device and enumerate this device for an image item. But now, when I try to transfer an image, I'm stuck. If I use the root item for data transfer pWiaDataTransfer->idtGetData returns a HRESULT of 0x8000FFFF (E_UNEXPECTED), if I use the image item (there are only two items 'root' and 'top' on my device) it fails when I obtain the storage interface. I thought maybe I needed to obtain the storage interface from 'root' and the data transfer interface from 'top' but that also fails (when I try to obtain the data transfer interface). I then get 0x80004002 (E_NOINTERFACE - No such interface supported.). Here is the code:

HRESULT TransferWiaItem( IWiaItem *pWiaItem, IWiaItem *pWiaItem2 )
{
    IWiaPropertyStorage *pWiaPropertyStorage = NULL;
    HRESULT hr = pWiaItem->QueryInterface( IID_IWiaPropertyStorage, (void**)&pWiaPropertyStorage );
    if( SUCCEEDED( hr ) )
    {
        PROPSPEC PropSpec[2] = {0};
        PROPVARIANT PropVariant[2] = {0};
        const ULONG c_nPropCount = sizeof(PropVariant)/sizeof(PropVariant[0]);
        GUID guidOutputFormat = WiaImgFmt_BMP;
        PropSpec[0].ulKind = PRSPEC_PROPID;
        PropSpec[0].propid = WIA_IPA_FORMAT;
        PropSpec[1].ulKind = PRSPEC_PROPID;
        PropSpec[1].propid = WIA_IPA_TYMED;
        PropVariant[0].vt = VT_CLSID;
        PropVariant[0].puuid = &guidOutputFormat;
        PropVariant[1].vt = VT_I4;
        PropVariant[1].lVal = TYMED_FILE;
        hr = pWiaPropertyStorage->WriteMultiple( c_nPropCount, PropSpec, PropVariant, WIA_IPA_FIRST );
        if( SUCCEEDED( hr ) )
        {
            IWiaDataTransfer *pWiaDataTransfer = NULL;
            hr = pWiaItem2->QueryInterface( IID_IWiaDataTransfer, (void**)&pWiaDataTransfer );
            if( SUCCEEDED( hr ) )
            {
                CWiaDataCallback *pCallback = new CWiaDataCallback;
                if( pCallback )
                {
                    IWiaDataCallback *pWiaDataCallback = NULL;
                    hr = pCallback->QueryInterface( IID_IWiaDataCallback, (void**)&pWiaDataCallback );
                    if( SUCCEEDED( hr ) )
                    {
                        STGMEDIUM stgMedium = {0};
                        stgMedium.tymed = TYMED_FILE;
                        hr = pWiaDataTransfer->idtGetData( &stgMedium, pWiaDataCallback );
                        ...

Where pWiaItem is the 'root' item and pWiaItem2 is the 'top' item.

Anybody have a clue what is going on here?

Was it helpful?

Solution

The solution is to enumerate the items of the 'root' WiaItem in the local context again. I did this in an init method and stored the pointer to the 'top', somehow it seemed so that it got invalidated and the HRESULT did not reflect that. After I changed the code, so that the 'top' WiaItem gets identified right before I use it, everything went fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top