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

📄 debug.cpp

📁 WINDDK XP/2003 Microsoft Bitmap Printer Driver Sample Decompress to src in WINDDK and "build -cZ
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//  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  1996 - 2003  Microsoft Corporation.  All Rights Reserved.
//
//  FILE:   Debug.cpp
//    
//
//  PURPOSE:  Implementation of the COemUniDbg debug class and 
//          its associated debug functions.
//
//
//  Functions:
//          COemUniDbg constructor and destructor
//          COemUniDbg::OEMDebugMessage
//          COemUniDbg::OEMRealDebugMessage
//          COemUniDbg::StripDirPrefixA
//          COemUniDbg::EnsureLabel
//          COemUniDbg::vDumpFlags
//          COemUniDbg::vDumpOemDevMode
//          COemUniDbg::vDumpOemDMParam
//          COemUniDbg::vDumpSURFOBJ
//          COemUniDbg::vDumpSTROBJ
//          COemUniDbg::vDumpFONTOBJ
//          COemUniDbg::vDumpCLIPOBJ
//          COemUniDbg::vDumpBRUSHOBJ
//          COemUniDbg::vDumpGDIINFO
//          COemUniDbg::vDumpDEVINFO
//          COemUniDbg::vDumpBitmapInfoHeader
//          COemUniDbg::vDumpPOINTL
//          COemUniDbg::vDumpRECTL
//          COemUniDbg::vDumpXLATEOBJ
//          COemUniDbg::vDumpCOLORADJUSTMENT
//
//
//
//  PLATFORMS:  Windows XP, Windows Server 2003
//
//
//  History: 
//          06/28/03    xxx created.
//
//

#include "precomp.h"
#include "bitmap.h"
#include "devmode.h"
#include "debug.h"

// StrSafe.h needs to be included last
// to disallow bad string functions.
//#include <STRSAFE.H>



////////////////////////////////////////////////////////
//      INTERNAL DEFINES
////////////////////////////////////////////////////////

#define DEBUG_BUFFER_SIZE       1024
#define PATH_SEPARATOR          '\\'
#define MAX_LOOP                10

// Determine what level of debugging messages to eject. 
#ifdef VERBOSE_MSG
    #define DEBUG_LEVEL     DBG_VERBOSE
#elif TERSE_MSG
    #define DEBUG_LEVEL     DBG_TERSE
#elif WARNING_MSG
    #define DEBUG_LEVEL     DBG_WARNING
#elif ERROR_MSG
    #define DEBUG_LEVEL     DBG_ERROR
#elif RIP_MSG
    #define DEBUG_LEVEL     DBG_RIP
#elif NO_DBG_MSG
    #define DEBUG_LEVEL     DBG_NONE
#else
    #define DEBUG_LEVEL     DBG_WARNING
#endif



////////////////////////////////////////////////////////
//      EXTERNAL GLOBALS
////////////////////////////////////////////////////////

INT giDebugLevel = DEBUG_LEVEL;

////////////////////////////////////////////////////////////////////////////////
//
// COemUniDbg body
//

__stdcall COemUniDbg::COemUniDbg(
    INT     iDebugLevel,
    PWSTR   pszInTag
    )
{
    // Do any init stuff here.
    //

    // Check if the debug level is appropriate to output the tag
    //
    if (iDebugLevel >= giDebugLevel)
    {
        PCWSTR pszTag = EnsureLabel(pszInTag, L"??? function entry.");
        OEMDebugMessage(DLLTEXT("%s\r\n"), pszTag);
    }
}

__stdcall COemUniDbg::~COemUniDbg(
    VOID
    )
{
    // Do any cleanup stuff here.
    //
}

BOOL __stdcall
COemUniDbg::
OEMDebugMessage(
    LPCWSTR lpszMessage, 
    ...
    )

/*++

Routine Description:

    Outputs variable argument debug string.
    
Arguments:

    lpszMessage - format string

Return Value:

    TRUE if successful, FALSE if there is an error

--*/

{
    BOOL    bResult;
    va_list VAList;

    // Pass the variable parameters to OEMRealDebugMessage to be processed.
    va_start(VAList, lpszMessage);
    bResult = OEMRealDebugMessage(MAX_PATH, lpszMessage, VAList);
    va_end(VAList);

    return bResult;
}


BOOL __stdcall
COemUniDbg::
OEMRealDebugMessage(
    DWORD       dwSize, 
    LPCWSTR lpszMessage, 
    va_list     arglist
    )

/*++

Routine Description:

    Outputs variable argument debug string.
    
Arguments:

    dwSize - size of temp buffer to hold formatted string
    lpszMessage - format string
    arglist - Variable argument list...

Return Value:

    TRUE if successful, FALSE if there is an error

--*/

{
    LPWSTR      lpszMsgBuf;
    HRESULT     hResult;

    // Parameter checking.
    if( (NULL == lpszMessage)
        ||
        (0 == dwSize) )
    {
        return FALSE;
    }

    // Allocate memory for message buffer.
    lpszMsgBuf = new WCHAR[dwSize + 1];    
    if(NULL == lpszMsgBuf)
        return FALSE;

    // Pass the variable parameters to wvsprintf to be formated.
    // hResult = StringCbVPrintfW(lpszMsgBuf, (dwSize + 1) * sizeof(WCHAR), lpszMessage, arglist);
	hResult = wsprintf(lpszMsgBuf, lpszMessage, arglist);

    // Dump string to debug output.
    OutputDebugStringW(lpszMsgBuf);

    // Clean up.
    delete[] lpszMsgBuf;

    return SUCCEEDED(hResult);
}

PCSTR __stdcall
COemUniDbg::
StripDirPrefixA(
    IN PCSTR    pstrFilename
    )

/*++

Routine Description:

    Strip the directory prefix off a filename (ANSI version)

Arguments:

    pstrFilename - Pointer to filename string

Return Value:

    Pointer to the last component of a filename (without directory prefix)

--*/

{
    PCSTR   pstr;

    if (pstr = strrchr(pstrFilename, PATH_SEPARATOR))
        return pstr + 1;

    return pstrFilename;
}

PCWSTR __stdcall
COemUniDbg::
EnsureLabel(
    PCWSTR      pszInLabel, 
    PCWSTR      pszDefLabel
    )

/*++

Routine Description:

    This function checks if pszInLabel is valid. If not, it returns
    pszDefLabel else pszInLabel is returned.
    
Arguments:

    pszInLabel - custom label string passed in with the call to the dump function
    pszDefLabel - default label string in case custom label string is not valid

Return Value:

    pszInLabel if it is valid, else pszDefLabel

--*/

{
    // By design, pszDefLabel is assumed to be a valid, non-empty
    // string (since it is supplied internally).
    //
    if (!pszInLabel || !*pszInLabel)
    {
        // The caller supplied a NULL string or empty string;
        // supply the internal default.
        //
        return pszDefLabel;
    }
    return pszInLabel;
}

void __stdcall
COemUniDbg::
vDumpFlags(
    DWORD           dwFlags,
    PDBG_FLAGS      pDebugFlags
    )

/*++

Routine Description:

    Dumps the combination of flags in members such as 
    pso->fjBitmap, pstro->flAccel, pfo->flFontType etc.
    
Arguments:

    dwFlags - combined value of the relevant member
        Example values are pso->fjBitmap, pstro->flAccel
    pDebugFlags - structure containing the different possible values
        that can be combined in dwFlags

Return Value:

    NONE

--*/

{
    DWORD dwFound = 0;
    BOOL bFirstFlag = FALSE;

    OEMDebugMessage(TEXT( "%#x ["), dwFlags);

    // Traverse through the list of flags to see if any match
    //
    for ( ; pDebugFlags->dwFlag; ++pDebugFlags)
    {
        if(dwFlags & pDebugFlags->dwFlag)
        {
            if (!bFirstFlag)
            {
                OEMDebugMessage(TEXT("%s"), pDebugFlags->pszFlag);
                bFirstFlag = TRUE;
            }
            else
            {
                OEMDebugMessage(TEXT(" | %s"), pDebugFlags->pszFlag);
            }
            dwFound |= pDebugFlags->dwFlag;
        }
    }

    OEMDebugMessage(TEXT("]"));

    //
    // Check if there are extra bits set that we don't understand.
    //
    if(dwFound != dwFlags)
    {
        OEMDebugMessage(TEXT("  <ExtraBits: %x>"), dwFlags & ~dwFound);
    }

    OEMDebugMessage(TEXT("\r\n"));
}

void __stdcall
COemUniDbg::
vDumpOemDevMode(
    INT             iDebugLevel,
    PWSTR           pszInLabel,
    PCOEMDEV        pOemDevmode
    )

/*++

Routine Description:

    Dumps the members of a private OEM devmode (OEMDEV) structure.
    
Arguments:

    iDebugLevel - desired output debug level
    pszInLabel - output label string
    pOemDevmode - pointer to the OEMDEV strct to be dumped

Return Value:

    NONE

--*/

{
    // Check if the debug level is appropriate
    //
    if (iDebugLevel < giDebugLevel)
    {
        // Nothing to output here
        //
        return;
    }
    
    // Prepare the label string
    //
    PCWSTR pszLabel = EnsureLabel(pszInLabel, L"pOemDevMode");
    
    // Return if strct to be dumped is invalid
    //
    if (!pOemDevmode)
    {
        OEMDebugMessage(TEXT("\npOemDevmode [%s]: NULL\r\n"), pszLabel);

        // Nothing else to output
        //
        return;
    }

    // Format the data
    //
    OEMDebugMessage(TEXT("\npOemDevmode [%s]: %#x\r\n"), pszLabel, pOemDevmode);

    if ((pOemDevmode->dmOEMExtra.dwSize >= sizeof(OEMDEV))
        &&
        (OEM_SIGNATURE == pOemDevmode->dmOEMExtra.dwSignature))
    {
        OEMDebugMessage(TEXT("\tdmOEMExtra.dwSize: %d\r\n"), pOemDevmode->dmOEMExtra.dwSize);
        OEMDebugMessage(TEXT("\tdmOEMExtra.dwSignature: %#x\r\n"), pOemDevmode->dmOEMExtra.dwSignature);
        OEMDebugMessage(TEXT("\tdmOEMExtra.dwVersion: %#x\r\n"), pOemDevmode->dmOEMExtra.dwVersion);
        OEMDebugMessage(TEXT("\tdwDriverData: %#x\r\n"), pOemDevmode->dwDriverData);
    }
    else
    {
        OEMDebugMessage(TEXT("\tUnknown private OEM DEVMODE.\r\n"));
    }

    OEMDebugMessage(TEXT("\n"));
}


void __stdcall
COemUniDbg::
vDumpOemDMParam(
    INT             iDebugLevel,
    PWSTR           pszInLabel,
    POEMDMPARAM pOemDMParam
    )

⌨️ 快捷键说明

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