uLib
User mode C/C++ extended API library for Win32 programmers.
|
Flexible debug output and system error messages.
#include <uLib/Debug.h>
The default settings are dbg_Level = DP_DEBUG, dbg_LogFile = NULL, and dbg_Name = "[uLib]",
so a typical debugging ingress in WinMain might be...
Groups | |
DPrint Levels | |
DPrint severity filtering thresholds... | |
Conditional Debugging Macros | |
These macros are active in _DEBUG builds, and voided in Release builds. | |
Macros | |
#define | _F(s) _T("[") _T(__FUNCTION__) _T("] ") _T(s) |
#define | DP_StdFailMsg(What) DPrint( DP_ERROR, What _T(" failed: %s\n"), SysErrorMsg() ) |
Functions | |
void __cdecl | DPrint (int Level, CSTR Fmt,...) |
CSTR | SysErrorMsg (DWORD Err=0, TSTR Buf=NULL, UINT Length=0) |
CSTR | NtErrorMsg (NTSTATUS Status=0, TSTR Buf=NULL, UINT Size=0) |
bool | SetLastErrorFromNtStatus (NTSTATUS Status) |
ACSTR | GetWinMsgName (WORD msgId) |
ACSTR | GetExceptionName (DWORD xCode) |
int | SetDebugLevel (int Level) |
HANDLE | OpenLogFile (CSTR Name, bool Append) |
CSTR | DefaultLogFileName (HMODULE hModule) |
Variables | |
CSTR | dbg_Name |
int | dbg_Level |
HANDLE | dbg_LogFile |
bool | dbg_Flush |
#define _F | ( | s | ) | _T("[") _T(__FUNCTION__) _T("] ") _T(s) |
void __cdecl DPrint | ( | int | Level, |
CSTR | Fmt, | ||
... | |||
) |
DPrint outputs a string to the debugger if Level <= dbg_Level.
The output string has the format "dbg_Name LEVEL: Fmt and inserts".
If dbg_LogFile is not NULL, the string is written to the log file as well.
Level zero messages are meant to always be emitted.
To squelch all output, set dbg_Level = -1.
Text is formatted with _vstprintf_s into an internal buffer of 512 chars.
See also dbg_Name, dbg_Level
SysErrorMsg returns the system defined error message for the Err code.
If Err zero is passed in, the error is queried with GetLastError().
If a Buf is passed in, it is used to return the error string.
If Buf is NULL and Length is non-zero, Buf is allocated with newStrBuf().
If Buf is NULL and Length is zero, an internal static buffer is used.
NtErrorMsg is an experimental wrap for SysErrorMsg,
using LsaNtStatusToWinError() to translate the NTSTATUS..
Will the error code translations make sense ?
bool SetLastErrorFromNtStatus | ( | NTSTATUS | Status | ) |
Get a string representation of a windows message, e.g "WM_CONTEXTMENU".
In a release build this only returns "WM_<hex>(<decimal>)".
Definition at line 37 of file MsgTbl.cpp.
Get a string representation of an exception code, e.g "EXCEPTION_ACCESS_VIOLATION".
In a release build this only returns "Exception <hex>".
Definition at line 641 of file MsgTbl.cpp.
int SetDebugLevel | ( | int | Level | ) |
HANDLE OpenLogFile | ( | CSTR | Name, |
bool | Append | ||
) |
Open a debugging log file, suitable for dbg_LogFile.
If Name is NULL, the file name is generated with DefaultLogFileName().
If Append is true, the file pointer is moved to the end of the file.
CSTR DefaultLogFileName | ( | HMODULE | hModule | ) |
HANDLE dbg_LogFile |