I can see a couple of problems.
First of all here:
LPTSTR message = s.str().c_str();
The call to s.str()
returns a temporary which will be destroyed unless you keep it alive. Therefore the address returned by calling c_str()
becomes invalid. You need a temporary local:
string str = s.str();
LPCTSTR message = str.c_str();
And since c_str()
returns a const C string, you need to declare message to be a const C string too.
The other problem is that your Log
function receives a non-const C string, but c_str()
returns a const C string. Presumably the Log
function does not need to modify the message, so why are you asking for a modifiable buffer. Change Log
to receive a const C string:
void Log(..., LPCTSTR szMsgString, ...)
Finally, since this is C++, why are you using C strings at all? It is better to use C++ strings.