void 
dbgprint(
    char *format,
    ...
    )
{
    static  DWORD pid=0;
    va_list vl;
    char    dbgbuf1[2048],
            dbgbuf2[2048];

    // Prepend the process ID to the message
    if ( 0 == pid )
    {
        pid = GetCurrentProcessId();
    }

    EnterCriticalSection(&gDebugCritSec);
    va_start(vl, format);
    StringCbVPrintf(dbgbuf1, sizeof(dbgbuf1),format, vl);
    StringCbPrintf(dbgbuf2, sizeof(dbgbuf2),"%lu: %s\r\n", pid, dbgbuf1);
    va_end(vl);

    OutputDebugString(dbgbuf2);
    LeaveCriticalSection(&gDebugCritSec);
}
Exemplo n.º 2
0
/*static*/ string string::format(const char * fmt, ...)
{
	va_list va;
	va_start(va, fmt);

	int len = 1024;
	char * buf = new char[len];
	HRESULT hr = 0;

	for(;;)
	{
		hr = StringCbVPrintf(buf, len, fmt, va);
		if(hr==STRSAFE_E_INSUFFICIENT_BUFFER)
		{
			len+=1024;
			delete buf;
			buf = new char[len];
		}
		else
			break;
	}

	string s2(buf);
	delete buf;
	return s2;
}
Exemplo n.º 3
0
Arquivo: Log.cpp Projeto: zyy329/Tools
void CLog::LogMsg( EErrorMsg_Type eType, const TCHAR * pszParam,... )
{
    if ( m_bRunLog == false )       // 日志已关闭
    {
        return;
    }

    static const int BUF_SIZE = 4096;
    TCHAR szCharBuf[BUF_SIZE];
    memset( &szCharBuf, 0x00, sizeof(szCharBuf) );

    // va string
    va_list va; 
    va_start(va, pszParam); 

    StringCbVPrintf(szCharBuf, BUF_SIZE, pszParam, va);

    va_end(va);
    

    // add
    S_LogMsg* pLog = ms_LogPool.Pool_Pop();
    pLog->eType = eType;
    pLog->strMsg = szCharBuf;

    m_lstLogMsg.push_back( pLog );
}
Exemplo n.º 4
0
KHMEXP kherr_event * __cdecl
kherr_reportf(const wchar_t * long_desc_fmt, ...)
{
    va_list vl;
    wchar_t buf[1024];
    kherr_event * e;

    va_start(vl, long_desc_fmt);
    StringCbVPrintf(buf, sizeof(buf), long_desc_fmt, vl);
    va_end(vl);

    e = kherr_report(KHERR_DEBUG_1,
                     NULL, NULL, NULL, buf, NULL, 0,
                     KHERR_SUGGEST_NONE, _vnull(), _vnull(), _vnull(), _vnull(),
                     KHERR_RF_CSTR_LONG_DESC
#ifdef _WIN32
                     ,NULL
#endif
                     );
    if (IS_KHERR_EVENT(e)) {
        kherr_evaluate_event(e);
    }

    return e;
}
Exemplo n.º 5
0
void ShowDebug(PCTSTR format, ...)
{
    va_list args;
    va_start(args, format);

    TCHAR string[MAX_PATH];

    StringCbVPrintf(string, sizeof(string), format, args);
    
	MessageBox(NULL, string, NULL, MB_OK);
}
Exemplo n.º 6
0
VOID CFormatMessage::OutputDebugString(LPCTSTR szFormat,...)
{
	va_list vagrc;
	va_start(vagrc,szFormat);
	TCHAR szParamText[2048]={NULL};
	StringCbVPrintf(szParamText,sizeof(szParamText),szFormat,vagrc);
	va_end(vagrc);
	INT nLen = _tcslen(szParamText);
	StringCbPrintf(&szParamText[nLen],sizeof(szParamText)-nLen,TEXT("\r\n╢МнСт╜рР:(%d)%s"),m_nLastError,szErrorText);
	::OutputDebugString(szParamText);
}
Exemplo n.º 7
0
KHMEXP void
kherr_debug_printf(wchar_t * fmt, ...)
{
    va_list vl;
    wchar_t buf[1024];

    va_start(vl, fmt);
    StringCbVPrintf(buf, sizeof(buf), fmt, vl);
    OutputDebugString(buf);
    va_end(vl);
}
Exemplo n.º 8
0
void DBGMSG(PCWSTR format, ...)
{
    va_list args;
    va_start(args, format);

    WCHAR msg[MAX_PATH];

    if (SUCCEEDED(StringCbVPrintf(msg, sizeof(msg), format, args)))
    {
        //OutputDebugString(msg);
		fprintf(stderr, "%S", msg);
    }
}
Exemplo n.º 9
0
void MyTrace(LPCTSTR lpszFormat,...)
{
	TCHAR szBuffer[512];	// it may be long buffer

	va_list args;
	va_start(args, lpszFormat);

	StringCbVPrintf(szBuffer, _countof(szBuffer), lpszFormat, args);

	MyOutputDebugString((LPCTSTR)szBuffer);

	va_end(args);
}
Exemplo n.º 10
0
static void DBGMSG(PCWSTR format, ...)
{
	va_list args;
	va_start(args, format);

	WCHAR msg[MAX_PATH];

	if (SUCCEEDED(StringCbVPrintf(msg, sizeof(msg), format, args)))
	{
		char *cmsg;
		os_wcs_to_utf8_ptr(msg, 0, &cmsg);
		MF_LOG(LOG_INFO, "%s", cmsg);
		bfree(cmsg);
	}
}
Exemplo n.º 11
0
void StatusWindow::Print(const TCHAR *format, ...)
{
	va_list args;
	static char buffer[4096];
	static CommandLogMessage cmdLogMessage;

	va_start(args, format);
    HRESULT pfok = StringCbVPrintf(buffer, 4096, format, args);
	va_end(args);
	
	if(pfok == S_OK || pfok == STRSAFE_E_INSUFFICIENT_BUFFER) {
		cmdLogMessage.message = buffer;
		SendCommand(&cmdLogMessage);
	}
}
Exemplo n.º 12
0
void DBGMSG(PCWSTR format, ...)
{
    va_list args;
    va_start(args, format);

    WCHAR string[MAX_PATH];

    if (SUCCEEDED(StringCbVPrintf(string, sizeof(string), format, args)))
    {
        OutputDebugString(string);
    }
    else
    {
        DebugBreak();
    }
}
Exemplo n.º 13
0
void __cdecl MyPrintf(LPCTSTR lpszFormat, ...)
{
    TCHAR szOutput[2048];
    va_list v1 = NULL;
    HRESULT hr = S_OK;

    va_start(v1, lpszFormat);
    hr = StringCbVPrintf(szOutput, sizeof(szOutput), lpszFormat, v1);
    if (SUCCEEDED(hr))
    {
        OutputDebugString(szOutput);
        _tprintf(szOutput);
    }
    else
    {
        _tprintf(_T("StringCbVPrintf failed with %X\n"), hr);
    }
}
Exemplo n.º 14
0
void DebugEvent(char *b,...) 
{
    HANDLE h; char *ptbuf[1],buf[MAXBUF_+1];
    va_list marker;

    if (!ISLOGONTRACE(TraceOption))
        return;

    h = RegisterEventSource(NULL, AFS_LOGON_EVENT_NAME);
    if (h != INVALID_HANDLE_VALUE) {
        va_start(marker,b);
        StringCbVPrintf(buf, MAXBUF_+1,b,marker);
        buf[MAXBUF_] = '\0';
        ptbuf[0] = buf;
        ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 1008, NULL, 1, 0, (const char **)ptbuf, NULL);
        DeregisterEventSource(h);
        va_end(marker);
    }
}
Exemplo n.º 15
0
static void
write_status(LPCTSTR lpFmt, ...)
{
    va_list args;
    TCHAR szTxt[128];
    CONSOLE_SCREEN_BUFFER_INFO csbi;

    va_start(args, lpFmt);
    StringCbVPrintf(szTxt, sizeof(szTxt), lpFmt, args);
    va_end(args);

    if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
    {
        _tprintf(_T("\r%*.*s"), -(csbi.dwSize.X - 1), csbi.dwSize.X - 1, szTxt);
    }
    else
    {
        _putts(szTxt);
    }
}
Exemplo n.º 16
0
	void GCDebugMsg(bool debuggerBreak, const char *format, ...)
	{
		// [ggrossman 09.24.04]
		// Changed this to _DEBUG only because we don't link to
		// CRT in Release builds, so vsprintf is unavailable!!
#if defined (_DEBUG) && !defined(UNDER_CE)
		va_list argptr;
		va_start(argptr, format);
		int bufferSize = _vscprintf(format, argptr)+1;

		char *buffer = (char*)alloca(bufferSize+2);
		if (buffer) {
			StringCbVPrintf(buffer, bufferSize+1, format, argptr);
			GCDebugMsg(buffer, debuggerBreak);
		}
#else
		(void)debuggerBreak;
		(void)format;
#endif
	}
Exemplo n.º 17
0
VOID
WriteDebugLog(LPSTR lpFile, UINT iLine, LPSTR lpFunc, LPWSTR lpMsg, ...)
{
    LARGE_INTEGER FileSize, MoveTo, NewPos;
    WCHAR szMsg[MAX_STR_LEN * 3];
    WCHAR szText[MAX_STR_LEN * 4], szTime[MAX_STR_LEN];
    DWORD dwBytesWritten;
    va_list args;

    if (!hDebugLog || hDebugLog == INVALID_HANDLE_VALUE)
        return;

    MoveTo.QuadPart = 0;
    if (!SetFilePointerEx(hDebugLog, MoveTo, &NewPos, FILE_END))
        return;

    if (!GetFileSizeEx(hDebugLog, &FileSize))
        return;

    LockFile(hDebugLog, (DWORD_PTR)NewPos.QuadPart, 0, (DWORD_PTR)FileSize.QuadPart, 0);

    GetTimeFormat(LOCALE_USER_DEFAULT,
                  0, NULL, NULL, szTime,
                  MAX_STR_LEN);

    va_start(args, lpMsg);
    StringCbVPrintf(szMsg, sizeof(szMsg), lpMsg, args);
    va_end(args);

    StringCbPrintf(szText, sizeof(szText),
                   L"[%s] %S:%ld %S(): \"%s\"\r\n",
                   szTime, lpFile, iLine, lpFunc, szMsg);

    WriteFile(hDebugLog, szText,
              wcslen(szText) * sizeof(WCHAR),
              &dwBytesWritten, NULL);

    UnlockFile(hDebugLog, (DWORD_PTR)NewPos.QuadPart, 0, (DWORD_PTR)FileSize.QuadPart, 0);
}
Exemplo n.º 18
0
void DebugPrintf( const TCHAR *fmt, ... )
{
//	return;

	va_list v;
	TCHAR buf[1024*4];
	int len;

	va_start( v, fmt );
	len = StringCbVPrintf( buf, sizeof(buf) / sizeof(TCHAR), fmt, v );
	va_end( v );

	if ( S_OK != len )
	{
		assert(false);
	}

	OutputDebugString( buf );
	OutputDebugString( TEXT("\r\n") );

	CLogManager::getInstance().Output(buf);
}
Exemplo n.º 19
0
void 
DbgPrt(
    __in HANDLE   hWnd,
    __in __nullterminated PCHAR   lpszFormat,
    ... 
    )
{
    char    buf[STRING_SIZE]; // = "WIN1394: ";
    va_list ap;

    va_start(ap, lpszFormat);

//    wvsprintf( &buf[0], lpszFormat, ap );
    StringCbVPrintf( &buf[0] , (STRING_SIZE * sizeof(buf[0])) , lpszFormat, ap ); 
#if defined(DBG)
    OutputDebugStringA(buf);
#endif

    if (hWnd)
        WriteTextToEditControl(hWnd, buf);

    va_end(ap);
}
Exemplo n.º 20
0
KHMEXP kherr_event * __cdecl
kherr_reportf_ex(enum kherr_severity severity,
                 const wchar_t * facility,
                 khm_int32 facility_id,
#ifdef _WIN32
                 HMODULE hModule,
#endif
                 const wchar_t * long_desc_fmt, ...)
{
    va_list vl;
    wchar_t buf[1024];
    kherr_event * e;

    va_start(vl, long_desc_fmt);
    StringCbVPrintf(buf, sizeof(buf), long_desc_fmt, vl);
#ifdef DEBUG
    if (IsDebuggerPresent())
        OutputDebugString(buf);
#endif
    va_end(vl);

    e = kherr_report(severity, NULL, facility, NULL, buf, NULL, facility_id,
                     KHERR_SUGGEST_NONE,
                     _vnull(),
                     _vnull(),
                     _vnull(),
                     _vnull(), KHERR_RF_CSTR_LONG_DESC
#ifdef _WIN32
                     ,hModule
#endif
                     );
    if (IS_KHERR_EVENT(e)) {
        kherr_evaluate_event(e);
    }

    return e;
}
Exemplo n.º 21
0
void LogMessage(CHAR *pszFormat, ... )
{
    
    //
    // output buffer -- note: hardcoded limit
    //

    static int const BUFFER_SIZE = 1280;

    char szBuffer[BUFFER_SIZE]; 


    //
    // get current time
    //

    SYSTEMTIME SystemTime;

    GetLocalTime(&SystemTime);

    
    //
    // format thread id and time
    //

    StringCbPrintf( szBuffer, BUFFER_SIZE, "[%lx]:[%02u:%02u:%02u.%03u]::",
             GetCurrentThreadId(),
             SystemTime.wHour,
             SystemTime.wMinute,
             SystemTime.wSecond,
             SystemTime.wMilliseconds);


    size_t iStringLength = 0;

    HRESULT hr = StringCbLength(szBuffer, BUFFER_SIZE, &iStringLength);

    if (FAILED(hr))
    {
        // either this code is wrong, or someone else in the process corrupted 
        // our memory.
        return;
    }


    //
    // get the actual message
    //

    va_list vaArguments;

    va_start(vaArguments, pszFormat);


    size_t iBytesLeft = BUFFER_SIZE - iStringLength;


    //
    // not checking the return code of this function. even if it fails, we will
    // have a null-terminated string that we will be able to log.
    //

    StringCbVPrintf( &(szBuffer[iStringLength]), iBytesLeft, pszFormat, vaArguments);

    va_end(vaArguments);


    //
    // how big is the string now, and how many bytes do we have left?
    //

    hr = StringCbLength(szBuffer, BUFFER_SIZE, &iStringLength);

    if (FAILED(hr))
    {
        // either this code is wrong, or someone else in the process corrupted 
        // our memory.
        return;
    }

    iBytesLeft = BUFFER_SIZE - iStringLength;

    //
    // append a carriage return to the string. ignore the result code, the 
    // result string will be null-terminated no matter what.
    //

    StringCbCat(szBuffer, iBytesLeft, "\n");


    //
    // log the buffer 
    //

    printf(szBuffer);
}