2013年1月16日 星期三

Output Debug String

As we know, we can use API OutputDebugString to show string on output window, like,

OutputDebugString(" This is debug message. ");
OutputDebugStringW(L" This is debug message. ");

You also can attach some variable to the output string.

wchar_t* world = L"world";
wchar_t* szBuffer = new wchar_t[512];
wsprintf(szBuffer, _T(" Hello %s \n"),  world);
OutputDebugString(szBuffer);
delete[] szBuffer;

or

wchar_t* message = L"world !";

wchar_t* str = L" Hello ";
wchar_t* buffer = new wchar_t[sizeof(str)+sizeof(message)+1];
wcscpy(buffer, str);
wcscat(buffer, message);
OutputDebugStringW(buffer);


or

float value = 100;
wchar_t* szBuffer = new wchar_t[512];
wsprintf(szBuffer, L" My math grade is %d \n",   (int)value);
OutputDebugString(szBuffer);
delete[] szBuffer;

or

float value = 100;
char* szBuffer = new char[512];
sprintf(szBuffer, L" My math grade is %f \n",  value);
OutputDebugStringA(szBuffer);
delete[] szBuffer;




沒有留言:

張貼留言