예제 #1
0
/*++

Routine Name:

    CXPSArchive::CXPSArchive

Routine Description:

    CXPSArchive class constructor

Arguments:

    pReadStream    - Pointer to the print read stream
    pWriteStream   - Pointer to the print write stream

Return Value:

    None
    Throws CXDException(HRESULT) on an error

--*/
CXPSArchive::CXPSArchive(
    _In_ IPrintReadStream*  pReadStream,
    _In_ IPrintWriteStream* pWriteStream
    ) :
    m_pWriteStream(pWriteStream),
    m_pPkArchive(NULL),
    m_hPkArch(NULL)
{
    HRESULT hr = S_OK;

    //
    // Get the current directory to load the pk archive library
    //
    DWORD cchName = 0;
    TCHAR* szFileName = new(std::nothrow) TCHAR[MAX_PATH];

    if (SUCCEEDED(hr = CHECK_POINTER(szFileName, E_OUTOFMEMORY)))
    {
        cchName = GetModuleFileName(g_hInstance, szFileName, MAX_PATH);

        if (cchName == 0)
        {
            hr = GetLastErrorAsHResult();
        }
    }

    if (SUCCEEDED(hr) &&
        cchName > 0)
    {
        //
        // Remove the filespec
        //
        PathRemoveFileSpec(szFileName);

        try
        {
            //
            // Append the PK archive DLL name
            //
            CStringXD cstrPath(szFileName);
            cstrPath += TEXT("\\pkarch.dll");

            //
            // Try to load the PK archive DLL
            //
            m_hPkArch = LoadLibrary(cstrPath);
        }
        catch (CXDException& e)
        {
            hr = e;
        }
    }

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

    if (SUCCEEDED(hr))
    {
        //
        // Get DllGetClassObject from the PK archive and instantiate the PK archive handler
        //
        if (m_hPkArch != NULL)
        {
            GetClassObject pfnGetClassObject = reinterpret_cast<GetClassObject>(GetProcAddress(m_hPkArch, "DllGetClassObject"));

            if (SUCCEEDED(hr = CHECK_POINTER(pfnGetClassObject, E_NOINTERFACE)) &&
                SUCCEEDED(hr = pfnGetClassObject(CLSID_PKArchiveHandler, IID_IPKArchive, reinterpret_cast<LPVOID*>(&m_pPkArchive))))
            {
                hr = CHECK_POINTER(m_pPkArchive, E_NOINTERFACE);
            }
        }
        else
        {
            hr = E_NOINTERFACE;
        }
    }

    //
    // Initialise the IO streams
    //
    if (SUCCEEDED(hr) &&
        SUCCEEDED(hr = CHECK_POINTER(pReadStream, E_POINTER)) &&
        SUCCEEDED(hr = CHECK_POINTER(m_pWriteStream, E_POINTER)) &&
        SUCCEEDED(hr = m_pPkArchive->SetReadStream(pReadStream)) &&
        SUCCEEDED(hr = m_pPkArchive->SetWriteStream(m_pWriteStream)))
    {
        //
        // We can now process the read stream to create the file index
        //
        hr = m_pPkArchive->ProcessReadStream();
    }

    if (FAILED(hr))
    {
        throw CXDException(hr);
    }
}
예제 #2
0
파일: globals.cpp 프로젝트: kcrazy/winekit
/*++

Routine Name:

    GetLastErrorAsHResult

Routine Description:

    Converts a GDI status error to an HRESULT

Arguments:

    gdiPStatus - The GDI plus status value to be converted to an HRESULT

Return Value:

    HRESULT
    S_OK - On success
    E_*  - On error

--*/
HRESULT
GetGDIStatusErrorAsHResult(
    __in Status gdiPStatus
    )
{
    HRESULT hr = E_FAIL;

    switch (gdiPStatus)
    {
        case Ok:
        {
            hr = S_OK;
        }
        break;

        case GenericError:
        {
            hr = E_FAIL;
        }
        break;

        case InvalidParameter:
        {
            hr = E_INVALIDARG;
        }
        break;

        case OutOfMemory:
        {
            hr = E_OUTOFMEMORY;
        }
        break;

        case ObjectBusy:
        {
            hr = E_PENDING;
        }
        break;

        case InsufficientBuffer:
        {
            hr = E_OUTOFMEMORY;
        }
        break;

        case NotImplemented:
        {
            hr = E_NOTIMPL;
        }
        break;

        case Win32Error:
        {
            hr = GetLastErrorAsHResult();
        }
        break;

        case FileNotFound:
        {
            hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
        }
        break;

        case AccessDenied:
        {
            hr = HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED);
        }
        break;

        //
        // Default to E_FAIL
        //
        case UnknownImageFormat:
        case FontFamilyNotFound:
        case FontStyleNotFound:
        case NotTrueTypeFont:
        case UnsupportedGdiplusVersion:
        case GdiplusNotInitialized:
        case PropertyNotFound:
        case PropertyNotSupported:
        case ValueOverflow:
        case Aborted:
        case WrongState:
        default:
            break;
    };

    return hr;
}