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

📄 profman.cpp

📁 WDK 自带的xpsdrv filter之 color
💻 CPP
📖 第 1 页 / 共 2 页
字号:

    if (SUCCEEDED(hr = CHECK_POINTER(szProfile, E_POINTER)))
    {
        hr = SetProfileFromColDir(&m_srcProfile, szProfile);
    }

    ERR_ON_HR(hr);
    return hr;
}

/*++

Routine Name:

    CProfileManager::SetSrcProfileFromBuffer

Routine Description:

    Method which sets the source colour profile from a buffer

Arguments:

    pszProfile - Pointer to string holding the profile name
    pBuffer    - Pointer to buffer holding the profile data
    cbBuffer   - Count of bytes in the profile buffer

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT
CProfileManager::SetSrcProfileFromBuffer(
    __in                  LPWSTR szProfile,
    __in_bcount(cbBuffer) PBYTE  pBuffer,
    __in                  UINT   cbBuffer
    )
{
    HRESULT hr = S_OK;

    if (SUCCEEDED(hr = CHECK_POINTER(szProfile, E_POINTER)) ||
        SUCCEEDED(hr = CHECK_POINTER(pBuffer, E_POINTER)))
    {
        hr = m_srcProfile.SetProfile(szProfile, pBuffer, cbBuffer);
    }

    ERR_ON_HR(hr);
    return hr;
}

/*++

Routine Name:

    CProfileManager::GetProfileOption

Routine Description:

    This method retrieves the profile option set in the PrintTicket

Arguments:

    pProfileOption - Pointer to a profile option enumeration type to recieve the option

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT
CProfileManager::GetProfileOption(
    __out EProfileOption* pProfileOption
    )
{
    HRESULT hr = S_OK;

    if (SUCCEEDED(hr = CHECK_POINTER(pProfileOption, E_POINTER)))
    {
        *pProfileOption = m_cmProfData.cmProfile;
    }

    ERR_ON_HR(hr);
    return hr;
}

/*++

Routine Name:

    CProfileManager::WriteData

Routine Description:

    This method handles writing the destination profile to the container

Arguments:

    pStream - Pointer to a stream to write the resource out to

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT
CProfileManager::WriteData(
    __in IPartBase*         pResource,
    __in IPrintWriteStream* pStream
    )
{
    HRESULT hr = S_OK;

    if (SUCCEEDED(hr = CHECK_POINTER(pResource, E_POINTER)) &&
        SUCCEEDED(hr = CHECK_POINTER(pStream, E_POINTER)))
    {
        HANDLE hFile = NULL;

        //
        // Open the destination profile file from disk. We could use the
        // handle however we do not know whether we will get the ICC or DMP.
        //
        CComBSTR bstrProfile;
        if (SUCCEEDED(hr = GetDstProfileName(&bstrProfile)))
        {
            hFile = CreateFile(bstrProfile,
                               GENERIC_READ,
                               FILE_SHARE_READ,
                               NULL,
                               OPEN_EXISTING,
                               FILE_ATTRIBUTE_NORMAL,
                               NULL);

            if (hFile == INVALID_HANDLE_VALUE)
            {
                hr = GetLastErrorAsHResult();
            }
        }

        if (SUCCEEDED(hr))
        {
            //
            // Write profile data to stream
            //
            PBYTE pBuff = new BYTE[CB_COPY_BUFFER];
            hr = CHECK_POINTER(pBuff, E_OUTOFMEMORY);
            DWORD cbRead = 0;

            while (SUCCEEDED(hr))
            {
                if (ReadFile(hFile, pBuff, CB_COPY_BUFFER, &cbRead, NULL))
                {
                    if (cbRead > 0)
                    {
                        ULONG cbWritten = 0;
                        hr = pStream->WriteBytes(reinterpret_cast<LPVOID>(pBuff), cbRead, &cbWritten);

                        if (cbRead != cbWritten)
                        {
                            RIP("Failed to write all profile data.\n");

                            hr = E_FAIL;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    hr = GetLastErrorAsHResult();
                }
            }

            if (pBuff != NULL)
            {
                delete[] pBuff;
                pBuff = NULL;
            }
        }

        if (hFile != NULL &&
            hFile != INVALID_HANDLE_VALUE)
        {
            CloseHandle(hFile);
        }
        hFile = NULL;
    }

    ERR_ON_HR(hr);
    return hr;
}

/*++

Routine Name:

    CProfileManager::GetKeyName

Routine Description:

    Method to obtain a unique key for the resource being handled

Arguments:

    pbstrKeyName - Pointer to a string to hold the generated key

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT
CProfileManager::GetKeyName(
    __deref_out BSTR* pbstrKeyName
    )
{
    HRESULT hr = S_OK;

    if (SUCCEEDED(hr = CHECK_POINTER(pbstrKeyName, E_POINTER)))
    {
        SysFreeString(*pbstrKeyName);
        hr = m_cmProfData.cmProfileName.CopyTo(pbstrKeyName);
    }

    ERR_ON_HR(hr);
    return hr;
}

/*++

Routine Name:

    CProfileManager::GetResURI

Routine Description:

    Method to obtain the URI of the resource being handled

Arguments:

    pbstrResURI - Pointer to a string to hold the resource URI

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT
CProfileManager::GetResURI(
    __deref_out BSTR* pbstrResURI
    )
{
    HRESULT hr = S_OK;

    if (SUCCEEDED(hr = CHECK_POINTER(pbstrResURI, E_POINTER)))
    {
        try
        {
            CStringXDW cstrFileName(m_cmProfData.cmProfileName);
            CStringXDW cstrFileExt(PathFindExtension(cstrFileName));

            INT indFileExt = cstrFileName.Find(cstrFileExt);

            if (indFileExt > -1)
            {
                cstrFileName.Delete(indFileExt, cstrFileExt.GetLength());
            }

            //
            // Create a unique name for the profile for this print session using GetTickCount()
            //
            CStringXDW cstrURI;
            cstrURI.Format(L"/%s_%u%s", cstrFileName, GetTickCount(), cstrFileExt);

            *pbstrResURI = cstrURI.AllocSysString();
        }
        catch (CXDException& e)
        {
            hr = e;
        }
    }

    ERR_ON_HR(hr);
    return hr;
}

/*++

Routine Name:

    CProfileManager::SetProfileFromColDir

Routine Description:

    Set the named profile from the color directory. The method appends the specified
    file name to the color directory path and instructs the profile class to open the
    profile

Arguments:

    pProfile  - Pointer to the profile class that actually opens the profile
    szProfile - The profile file name

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT
CProfileManager::SetProfileFromColDir(
    __in CProfile* pProfile,
    __in LPWSTR    szProfile
    )
{
    HRESULT hr = S_OK;

    if (SUCCEEDED(hr = CHECK_POINTER(pProfile, E_POINTER)) &&
        SUCCEEDED(hr = CHECK_POINTER(szProfile, E_POINTER)))
    {
        try
        {
            CStringXDW cstrProfile;

            if (SUCCEEDED(hr = GetColDir(&cstrProfile)))
            {
                cstrProfile += L"\\";
                cstrProfile += szProfile;

                hr = pProfile->SetProfile(cstrProfile.GetBuffer());
            }
        }
        catch (CXDException& e)
        {
            hr = e;
        }
    }

    ERR_ON_HR(hr);
    return hr;
}

/*++

Routine Name:

    CProfileManager::GetColDir

Routine Description:

    Retrieves the color directory path

Arguments:

    pcstrColDir - Pointer to a string class that accepts the color directory path

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT
CProfileManager::GetColDir(
    __out CStringXDW* pcstrColDir
    )
{
    HRESULT hr = S_OK;

    if (SUCCEEDED(hr = CHECK_POINTER(pcstrColDir, E_POINTER)))
    {
        try
        {
            pcstrColDir->Empty();
            DWORD cbColDir = 0;
            if (!GetColorDirectory(NULL, NULL, &cbColDir))
            {
                pcstrColDir->Preallocate(cbColDir/sizeof(WCHAR));
                if (!GetColorDirectory(NULL, pcstrColDir->GetBuffer(), &cbColDir))
                {
                    hr = GetLastErrorAsHResult();
                }
            }
        }
        catch (CXDException& e)
        {
            hr = e;
        }
    }

    ERR_ON_HR(hr);
    return hr;
}


⌨️ 快捷键说明

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