Skip to content

Instantly share code, notes, and snippets.

@khiemdoan
Created June 27, 2019 09:54
Show Gist options
  • Save khiemdoan/fc1129e0bd9b0bdc7143c0cf8af2c557 to your computer and use it in GitHub Desktop.
Save khiemdoan/fc1129e0bd9b0bdc7143c0cf8af2c557 to your computer and use it in GitHub Desktop.
// KhiemDH - 2019-06-26
#ifndef _DBG_PRINT_KHIEMDH_
#define _DBG_PRINT_KHIEMDH_
#ifndef _DEBUG
#define DbgPrint(_exp, ...) __noop
#else
#include "windows.h"
#include "string"
void DbgPrint(const wchar_t* szFormat, ...);
void DbgPrint(const char* szFormat, ...);
void DbgPrint(const std::wstring sContent);
void DbgPrint(const std::string sContent);
// KhiemDH - 2019-06-26
// show content in Output Window, DebugView
void DbgPrint(const wchar_t* szFormat, ...)
{
va_list args;
std::wstring sContent;
va_start(args, szFormat);
const int length = _vscwprintf(szFormat, args) + 1;
sContent.resize(length);
_vsnwprintf_s(&sContent[0], sContent.size(), _TRUNCATE, szFormat, args);
DbgPrint(sContent);
va_end(args);
}
// KhiemDH - 2019-06-26
// show content in Output Window, DebugView
void DbgPrint(const char* szFormat, ...)
{
va_list args;
std::string sContent;
va_start(args, szFormat);
const int length = _vscprintf(szFormat, args) + 1;
sContent.resize(length);
_vsnprintf_s(&sContent[0], sContent.size(), _TRUNCATE, szFormat, args);
DbgPrint(sContent);
va_end(args);
}
// KhiemDH - 2019-06-26
// show content in Output Window, DebugView
void DbgPrint(const std::wstring sContent)
{
OutputDebugStringW(sContent.c_str());
if (IsDebuggerPresent())
{
OutputDebugStringW(L"\r\n");
}
}
// KhiemDH - 2019-06-26
// show content in Output Window, DebugView
void DbgPrint(const std::string sContent)
{
OutputDebugStringA(sContent.c_str());
if (IsDebuggerPresent())
{
OutputDebugStringA("\r\n");
}
}
#endif // _DEBUG
#endif // !_DBG_PRINT_KHIEMDH_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment