Trace.h
:::: Line 18 #include <strstream>
There is a couple of
std::strstream
objects in your code, but they have long been deprecated in favour of
std::stringstream
, the appropriate header to include is
<sstream>
.
:::: Line 24 & 25
http://msdn.microsoft.com/en-us/library/b0084kay(v=vs.80)
:::: Line 26
Replace
std::ostrstream
with
std::wstringstream
.
:::: Line 27 os << MESSAGE << std::ends; \
std::ends
is an artifact of using
std::strstream
, remove all occurrences.
:::: Line 29 os.freeze(0); \
Remove freeze(), same reason as above.
Trace.cpp
:::: Line 146 wss << counter << std::ends;
Remove
std::ends
.
:::: Line 204 & 205 (Forum: Line 49 & 50 in the latter half of trace.cpp)
1 2
|
char tmpbuf[14];
strftime( tmpbuf, 128, "%y%m%d %H%M%S\0", today);
|
Buffer overrun, possibly the reason for your garbled output? replace the 128 in strftime() with
_countof(tmpbuf)
.
:::: Line 235 (Forum: Line 80 in the latter half of trace.cpp)
Remove
std::ends
.
That'll solve the compile and run-time errors I've come across. A couple of suggestions to further clean up your code:-
:::: Lines 29 - 37 (assume I'm referring to the latter half of trace.cpp on the forums from now on)
Hex output using a stream,
1 2 3 4
|
std::wostringstream strm;
strm << L"0x" << setfill(L'0') << setw(4) << std::hex << GetCurrentThreadId();
entete += strm.str();
|
:::: Lines 49 - 59
There is typically a wide function for every winapi / c standard function you come across,
1 2
|
wchar_t tmpbuf[14];
wcsftime(tmpbuf, _countof(tmpbuf), L"%y%m%d %H%M%S", today);
|
:::: Lines 110 - 133
stringCopyAvecEspaces()
could be written as,
1 2 3 4 5 6
|
void CTrace::stringCopyAvecEspaces(std::wstring &dest, const std::wstring &source, const short maxLen)
{
dest.assign(maxLen, L' '); // resize dest to maxLen and assign space to each character
size_t len = source.length() > maxLen ? maxLen : source.length(); // truncate if source > maxLen
dest.replace(0, len, source.c_str(), len); // replace characters of dest with source
}
|
Note: I think you misunderstood my earlier post regarding mixing TCHAR with wide functions, don't use TCHARs, TEXT() or _T() now since you are focused on Unicode.
wchar_t
literals are prefixed with an L.
wchar_t example[] = L"hello";
.
If you can, avoid using C stdio functions (eg. printf() and it's derivatives), prefer C++ streams, iostream/fstream/stringstream.