Visual Studio Output Window Error - C++
Using Visual Studio 2008, I keep seeing this error in the output window:
_CrtDbgReport: String too long or IO Error
I have a lot of TRACE
macros scattered开发者_JAVA技巧 throughout my code used to dump information about error conditions: file path, line number, error, etc. I need to trace down the source of this error because it may be that information it is trying to dump to the output window is too long. What is the maximum length of the string the TRACE
macro can accept? Here is an example of how I typically use this macro:
TRACE(_T("CreateNotifyWindow : Failed to create handle for notify window thread.\r\n\tError: %d\r\n\tFile: %s\r\n\tLine: %d\r\n"), ::GetLastError(), _T(__FILE__), __LINE__);
Any thoughts would be appreciated. Thanks.
Ultimately I'll bet the problem is passing an object string instead of string.c_str() to the Macro. TRACE uses variadic argument passing to, ultimately, something that calls something in the vsnprintf() family for %s
processing. It cannot deal with objects because C
can not.
The maximum length for OutputDebugString is 4K bytes minus a fraction, due to the implementation.
You've got in the same trouble as I did. I got the answer to this question on the web, and I checked it out, which worked very well.
// Inside your main header like stdafx.h, add the following include directive
#include <locale.h>
// And inside your main implementation such as InitInstance()
// of your CWinApp derived application class,
// you can put the following locale designation function.
#ifdef _DEBUG
_tsetlocale(LC_ALL, _T("korean")); // you should set the country code of yours
#endif // _DEBUG
Now, you can see the correct wide character string on your debug output window. Good luck!
精彩评论