I am writing a C++ application, and I want to add a timestamp to OutputDebugString(). I already know that if I watch the application using DebugView, it automatically show timestamps. But for a particular reason I want to add TimeStamps to any string I pass to OutputDebugString().

What would some sample code be?

有帮助吗?

解决方案

You could use QueryPerformanceCounter and QueryPerformanceFrequency to get a high-resolution timestamp. If you set a variable to the value returned by QueryPerformanceCounter before your program really starts executing, you can achieve the same effect as debug view by subtracting this initial value from the current performance counter value when printing to a debug string. GetTickCount is another API you can use, although the resolution isn't as good.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top