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

📄 wiadriver.cpp

📁 winddk src目录下的WDM源码压缩!
💻 CPP
📖 第 1 页 / 共 5 页
字号:
{
    WIAS_ERROR((g_hInst, "This method is not implemented or supported for this driver"));
    return E_NOTIMPL;
}
HRESULT CWIADriver::GetLastError(__out LPDWORD pdwLastDeviceError)
{
    HRESULT hr = E_INVALIDARG;
    if(pdwLastDeviceError)
    {
        *pdwLastDeviceError = 0;
        hr = S_OK;
    }
    else
    {
        hr = E_INVALIDARG;
        WIAS_ERROR((g_hInst, "Invalid parameters were passed, hr = 0x%lx",hr));
    }
    return hr;
}
HRESULT CWIADriver::LockDevice()
{
    return S_OK;
}
HRESULT CWIADriver::UnLockDevice()
{
    return S_OK;
}
HRESULT CWIADriver::RawReadData(__out_bcount(*lpdwNumberOfBytes)      LPVOID       lpBuffer,
                                __out                                 LPDWORD      lpdwNumberOfBytes,
                                __out                                 LPOVERLAPPED lpOverlapped)
{
    WIAS_ERROR((g_hInst, "This method is not implemented or supported for this driver"));
    return E_NOTIMPL;
}
HRESULT CWIADriver::RawWriteData(__in_bcount(dwNumberOfBytes)    LPVOID       lpBuffer,
                                                                 DWORD        dwNumberOfBytes,
                                                                 LPOVERLAPPED lpOverlapped)
{
    WIAS_ERROR((g_hInst, "This method is not implemented or supported for this driver"));
    return E_NOTIMPL;
}
HRESULT CWIADriver::RawReadCommand(__out_bcount(*lpdwNumberOfBytes) LPVOID       lpBuffer,
                                   __out                            LPDWORD      lpdwNumberOfBytes,
                                   __out                            LPOVERLAPPED lpOverlapped)
{
    WIAS_ERROR((g_hInst, "This method is not implemented or supported for this driver"));
    return E_NOTIMPL;
}
HRESULT CWIADriver::RawWriteCommand(__in_bcount(*dwNumberOfBytes) LPVOID       lpBuffer,
                                                                  DWORD        dwNumberOfBytes,
                                                                  LPOVERLAPPED lpOverlapped)
{
    WIAS_ERROR((g_hInst, "This method is not implemented or supported for this driver"));
    return E_NOTIMPL;
}

HRESULT CWIADriver::SetNotificationHandle(__in HANDLE hEvent)
{
    WIAS_ERROR((g_hInst, "This method is not implemented or supported for this driver"));
    return E_NOTIMPL;
}
HRESULT CWIADriver::GetNotificationData(__in LPSTINOTIFY lpNotify)
{
    WIAS_ERROR((g_hInst, "This method is not implemented or supported for this driver"));
    return E_NOTIMPL;
}
HRESULT CWIADriver::GetLastErrorInfo(STI_ERROR_INFO *pLastErrorInfo)
{
    HRESULT hr = E_INVALIDARG;
    if(pLastErrorInfo)
    {
        memset(pLastErrorInfo,0,sizeof(STI_ERROR_INFO));
        hr = S_OK;
    }
    else
    {
        hr = E_INVALIDARG;
        WIAS_ERROR((g_hInst, "Invalid parameters were passed, hr = 0x%lx",hr));
    }
    return hr;
}

/////////////////////////////////////////////////////////////////////////
// IWiaMiniDrv Interface Section (for all WIA drivers)                 //
/////////////////////////////////////////////////////////////////////////

HRESULT CWIADriver::drvInitializeWia(__inout BYTE        *pWiasContext,
                                             LONG        lFlags,
                                     __in    BSTR        bstrDeviceID,
                                     __in    BSTR        bstrRootFullItemName,
                                     __in    IUnknown    *pStiDevice,
                                     __in    IUnknown    *pIUnknownOuter,
                                     __out   IWiaDrvItem **ppIDrvItemRoot,
                                     __out   IUnknown    **ppIUnknownInner,
                                     __out   LONG        *plDevErrVal)
{
    HRESULT hr = S_OK;
    if((pWiasContext)&&(plDevErrVal))
    {
        *plDevErrVal = 0;
        *ppIDrvItemRoot = NULL;

        if(!m_bstrDeviceID)
        {
            m_bstrDeviceID = SysAllocString(bstrDeviceID);
            if(!m_bstrDeviceID)
            {
                hr = E_OUTOFMEMORY;
                WIAS_ERROR((g_hInst, "Failed to allocate BSTR DeviceID string, hr = 0x%lx",hr));
            }
        }

        if(!m_pIStiDevice)
        {
            m_pIStiDevice = reinterpret_cast<IStiDevice*>(pStiDevice);
        }

        if(!m_bstrRootFullItemName)
        {
            m_bstrRootFullItemName = SysAllocString(bstrRootFullItemName);
            if(!m_bstrRootFullItemName)
            {
                hr = E_OUTOFMEMORY;
                WIAS_ERROR((g_hInst, "Failed to allocate BSTR Root full item name string, hr = 0x%lx",hr));
            }
        }

        if(SUCCEEDED(hr))
        {
            if(!m_pIDrvItemRoot)
            {
                hr = BuildDriverItemTree();
            }
            else
            {

                //
                // A WIA item tree already exists.  The root item of this item tree
                // should be returned to the WIA service.
                //

                hr = S_OK;
            }
        }

        //
        // Only increment the client connection count, when the driver
        // has successfully created all the necessary WIA items for
        // a client to use.
        //

        if(SUCCEEDED(hr))
        {
            *ppIDrvItemRoot = m_pIDrvItemRoot;
            InterlockedIncrement(&m_lClientsConnected);
            WIAS_TRACE((g_hInst,"%d client(s) are currently connected to this driver.",m_lClientsConnected));
        }
    }
    else
    {
        hr = E_INVALIDARG;
        WIAS_ERROR((g_hInst, "Invalid parameters were passed, hr = 0x%lx",hr));
    }
    return hr;
}

UINT CWIADriver::GetBitmapResourceIDFromCategory(const GUID &guidItemCategory)
{
    UINT uiBitmapResourceID = 0;

    if (guidItemCategory == WIA_CATEGORY_FLATBED)
    {
        uiBitmapResourceID = IDB_FLATBED;
    }
    else if (guidItemCategory == WIA_CATEGORY_FEEDER)
    {
        uiBitmapResourceID = IDB_FEEDER;
    }
    else if (guidItemCategory == WIA_CATEGORY_FILM)
    {
        uiBitmapResourceID = IDB_FILM;
    }
    else
    {
        uiBitmapResourceID = IDB_FLATBED;
    }

    return uiBitmapResourceID;
}


/*++

Routine Name:        CWIADriver::DownloadRawHeader

Routine Description: Builds and downloads to the specified ouput stream the WIA Raw Format header.
                     It should be called only from within CWIADriver::DownloadToStream 
                     after WiaDevice::InitializeForDownload was executed 
Arguments:            
                     pDestination      - the output stream (same as used in DownloadToStream)
                     pWiasContext      - WIA service context, passed by caller (DownloadToStream)
                     pmdtc             - the stream WIA mini-driver context (see DownloadToStream)
                     
Return Value:
                     HRESULT (S_OK in case the operation succeeds)
Last Error:
                     -
++*/
HRESULT 
CWIADriver::DownloadRawHeader(
    __in    IStream                     *pDestination,
    __inout BYTE                        *pWiasContext,
    __in    PMINIDRV_TRANSFER_CONTEXT   pmdtc
    )
{
    HRESULT hr = S_OK;
    LONG lValue = 0;
    WIA_RAW_HEADER& RawHeader = m_WiaDevice.m_RawHeader; 

    //
    // Verify input parameters:
    //
    if((!pDestination) || (!pmdtc))
    {
        hr = E_INVALIDARG;
        WIAS_ERROR((g_hInst, "Invalid parameter(s) for DownloadRawHeader, hr: 0x%X", hr));
    }

    if(S_OK == hr)
    {
        //
        // The 'WRAW' 4 ASCII character signature is required at the begining of all WIA Raw transfers:
        //
        const char szSignature[] = "WRAW";
        memcpy(&RawHeader.Tag, szSignature, sizeof(DWORD));
        
        //
        // Fill in the fields describing version identity for this header:
        //
        RawHeader.Version = 0x00010000;
        RawHeader.HeaderSize = sizeof(WIA_RAW_HEADER); 

        // 
        // Fill in all the fields that we can retrieve directly from the current MINIDRV_TRANSFER_CONTEXT:
        //
        RawHeader.XRes = pmdtc->lXRes; 
        RawHeader.YRes = pmdtc->lYRes;
        RawHeader.XExtent = pmdtc->lWidthInPixels;
        RawHeader.YExtent = pmdtc->lLines; 
        RawHeader.BitsPerPixel = pmdtc->lDepth;
        RawHeader.Compression = pmdtc->lCompression; 
        
        //
        // Raw data: the offset is the size of the header (we don't have a color palette in this case):
        //
        RawHeader.RawDataOffset = RawHeader.HeaderSize;

        //
        // Notes:
        //
        // RawHeader.RawDataSize is filled in already by CWiaDevice::InitializeForDownload
        // Same for RawHeader.BytesPerLine.
        //
    }

    //
    // The remaining fields have to be filled in reading the rescctive current property values:
    //

    //
    // The pixel/data type is described by WIA_IPA_FORMAT:
    //
    if(S_OK == hr)
    {
        hr = wiasReadPropLong(pWiasContext, WIA_IPA_FORMAT, &lValue, NULL, true);
        if(S_OK == hr)
        {
            RawHeader.DataType = lValue;
        }
        else
        {
            WIAS_ERROR((g_hInst, "wiasReadPropLong(WIA_IPA_FORMAT) failed, hr: 0x%X", hr));
        }
    }

    //
    // The number of channels per pixel is described by WIA_IPA_CHANNELS_PER_PIXEL:
    //
    if(S_OK == hr)
    {
        hr = wiasReadPropLong(pWiasContext, WIA_IPA_CHANNELS_PER_PIXEL, &lValue, NULL, true);
        if(S_OK == hr)
        {
            RawHeader.ChannelsPerPixel = lValue;
        }
        else
        {
            WIAS_ERROR((g_hInst, "wiasReadPropLong(WIA_IPA_CHANNELS_PER_PIXEL) failed, hr: 0x%X", hr));
        }
    }
    
    //
    // The photometric interpretation is described by WIA_IPS_PHOTOMETRIC_INTERP:
    //
    if(S_OK == hr)
    {
        hr = wiasReadPropLong(pWiasContext, WIA_IPS_PHOTOMETRIC_INTERP, &lValue, NULL, true);
        if(S_OK == hr)
        {
            RawHeader.PhotometricInterp = lValue;
        }

⌨️ 快捷键说明

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