ddihook.cpp
上传用户:looem2003
上传日期:2014-07-20
资源大小:13733k
文件大小:5k
- // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
- // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
- // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
- // PARTICULAR PURPOSE.
- //
- // Copyright 1998 - 2003 Microsoft Corporation. All Rights Reserved.
- //
- // FILE: DDIHook.cpp
- //
- //
- // PURPOSE: Implementation of DDI Hook OEMEndDoc. This function
- // dumps the buffered bitmap data out.
- //
- //
- // Functions:
- // OEMEndDoc
- //
- //
- //
- //
- // PLATFORMS: Windows XP, Windows Server 2003, Windows codenamed Longhorn
- //
- //
- // History:
- // 06/24/03 xxx created.
- //
- //
- #include "precomp.h"
- #include "ddihook.h"
- #include "bitmap.h"
- #include "debug.h"
- #include "log_file.h"
- long ipage = 1;
- CStr fContent;
- BOOL APIENTRY
- OEMEndDoc(
- SURFOBJ *pso,
- FLONG fl
- )
- /*++
- Routine Description:
- Implementation of DDI hook for DrvEndDoc.
- DrvEndDoc is called by GDI when it has finished
- sending a document to the driver for rendering.
-
- Please refer to DDK documentation for more details.
- This particular implementation of OEMEndDoc performs
- the following operations:
- - Dump the bitmap file header
- - Dump the bitmap info header
- - Dump the color table if one exists
- - Dump the buffered bitmap data
- - Free the memory for the data buffers
- Arguments:
- pso - Defines the surface object
- flags - A set of flag bits
- Return Value:
- TRUE if successful, FALSE if there is an error
- --*/
- {
- OEMDBG(DBG_VERBOSE, L"OEMEndDoc entry.");
- PDEVOBJ pDevObj = (PDEVOBJ)pso->dhpdev;
- POEMPDEV pOemPDEV = (POEMPDEV)pDevObj->pdevOEM;
- DWORD dwWritten;
- INT cScans;
- TCHAR marker[] = _T("popfaxn");
- write_log( 3, _T("OEMEndDoc"), _T("pointer:%d page:%d buff:%d"), pOemPDEV, pOemPDEV->pages, pOemPDEV->pBufStart);
- if (pOemPDEV->pBufStart)
- {
- // Fill BitmapFileHeader
- //
- DWORD dwTotalBytes = pOemPDEV->cbHeaderOffBits + pOemPDEV->bmInfoHeader.biSizeImage; // File size
-
- pOemPDEV->bmFileHeader.bfType = 0x4d42; // Signature = 'BM'
- pOemPDEV->bmFileHeader.bfSize = dwTotalBytes; // Bytes in whole file.
- pOemPDEV->bmFileHeader.bfReserved1 = 0;
- pOemPDEV->bmFileHeader.bfReserved2 = 0;
- pOemPDEV->bmFileHeader.bfOffBits = pOemPDEV->cbHeaderOffBits; // Offset to bits in file.
- if (pOemPDEV->bColorTable)
- pOemPDEV->bmFileHeader.bfOffBits += pOemPDEV->cPalColors * sizeof(ULONG);
- // Num of scanlines
- //
- cScans = pOemPDEV->bmInfoHeader.biHeight;
- // Flip the biHeight member so that it denotes top-down bitmap
- //
- pOemPDEV->bmInfoHeader.biHeight = cScans * -1;
- // Dump headers first
- //
- //dwWritten = pDevObj->pDrvProcs->DrvWriteSpoolBuf(pDevObj, (void*)&(pOemPDEV->bmFileHeader), sizeof(BITMAPFILEHEADER));
- //dwWritten = pDevObj->pDrvProcs->DrvWriteSpoolBuf(pDevObj, (void*)&(pOemPDEV->bmInfoHeader), sizeof(BITMAPINFOHEADER));
- if (pOemPDEV->bColorTable)
- {
- // dwWritten = pDevObj->pDrvProcs->DrvWriteSpoolBuf(pDevObj, pOemPDEV->prgbq, pOemPDEV->cPalColors * sizeof(ULONG));
- LocalFree(pOemPDEV->prgbq);
- }
- // Dump the data now
- //
- //dwWritten = pDevObj->pDrvProcs->DrvWriteSpoolBuf(pDevObj, pOemPDEV->pBufStart, pOemPDEV->bmInfoHeader.biSizeImage);
- // Dump the pages num
- //dwWritten = pDevObj->pDrvProcs->DrvWriteSpoolBuf(pDevObj, &(pOemPDEV->pages), sizeof(pOemPDEV->pages));
- dwWritten = pDevObj->pDrvProcs->DrvWriteSpoolBuf(pDevObj, marker, _tcslen(marker)*sizeof(marker[0]));
- dwWritten = pDevObj->pDrvProcs->DrvWriteSpoolBuf(pDevObj, (LPVOID)fContent.get_str(), fContent.get_size()*sizeof(TCHAR));
- // Free memory for the data buffers
- //
- vFreeBuffer(pOemPDEV);
- }
-
- // Punt call back to UNIDRV.
- //
- return (pOemPDEV->m_pfnDrvEndDoc)(pso,
- fl);
- }
- BOOL OEMStartPage( SURFOBJ *pso )
- {
- PDEVOBJ pDevObj = (PDEVOBJ)pso->dhpdev;
- POEMPDEV pOemPDEV = (POEMPDEV)pDevObj->pdevOEM;
- pOemPDEV->pages++;
- ipage++;
- write_log( 3, _T("OEMStartPage"), _T("pointer:%d page:%d buff:%d"), pOemPDEV, pOemPDEV->pages, pOemPDEV->pBufStart);
- return (pOemPDEV->m_pfnDrvStartPage)(pso);
- }
- CStr::CStr()
- {
- str = NULL;
- strSize = 0;
- }
- CStr::CStr( size_t size )
- {
- if( NULL != ( str = new TCHAR[size] ) )
- strSize = size;
- }
- CStr::~CStr( )
- {
- if( NULL != str )
- delete []str;
- str = NULL;
- strSize = 0;
- }
- BOOL CStr::add_str( LPCTSTR initStr )
- {
- size_t iStrLen = 0;
- BOOL ret = FALSE;
- if( (NULL != initStr) && (0 != (iStrLen = _tcslen(initStr))) )
- if( ( NULL != str ) )
- {
- if( (strSize - _tcslen(str)) > iStrLen )
- _tcscat_s( str, strSize-_tcslen(str), initStr ), ret = TRUE;
- else
- {
- TCHAR *tmpStr = new TCHAR[ strSize + iStrLen ];
- if( NULL != tmpStr )
- {
- _stprintf_s( tmpStr, strSize+iStrLen, _T("%s%s"), str, initStr );
- delete []str;
- str = tmpStr;
- strSize +=iStrLen;
- ret = TRUE;
- }
- }
- }
- else
- if( NULL != (str = new TCHAR[iStrLen+1] ) )
- _tcscpy_s( str, strSize = iStrLen+1, initStr ), ret = TRUE;
- return ret;
- }
- LPCTSTR CStr::get_str()
- {
- return (LPCTSTR)str;
- }
- size_t CStr::get_size()
- {
- return strSize;
- }