In the debug state, the debugger such as the VC can capture the information output from OutputDebugString in the program. In fact, OutputDebugString is written to a piece of data into a shared image, and creates two Enevt, indicating that the data write event is triggered. In a non-debug state, we can also implement the output of OutputDebugString by programming. The following code demonstrates how to get this information:
DWORD WINAPI CDebugTrack :: TrackProc (PVOID pvParam) {HANDLE hMapping = NULL; HANDLE hAckEvent = NULL; PDEBUGBUFFER pdbBuffer = NULL; TCHAR tzBuffer [MAX_DebugBuffer]; _Try {// set the initial results m_dwResult = ERROR_INVALID_HANDLE; // open event handler hAckEvent = CreateEvent (NULL, FALSE, FALSE, TEXT ( "DBWIN_BUFFER_READY")); _LeaveIf (hAckEvent == NULL); m_hReadyEvent = CreateEvent (NULL, FALSE, FALSE, TEXT ( "DBWIN_DATA_READY")); _LeaveIf (m_hReadyEvent == NULL); // create a file mapping hMapping = CreateFileMapping (INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, MAX_DebugBuffer, TEXT ( "DBWIN_BUFFER")); _LeaveIf (hMapping == NULL); // maps debugging buffer pdbBuffer = (PDEBUGBUFFER) MapViewOfFile (hMapping, FILE_MAP_READ, 0, 0, 0); _LeaveIf (pdbBuffer == NULL); // loop for (m_dwResult = ERROR_SIGNAL_PENDING; (m_dwResult == ERROR_SIGNAL_PENDING);) {// wait for data buffer SetEvent (hAckEvent); if (WaitForSingleObject ( m_hreadyevent, infinite) == Wait_Object_0) {// If it is waiting, otherwise the main thread is A stop signal is input, the current thread if (m_dwResult == ERROR_SIGNAL_PENDING) {// add a new item _AStrToStr (tzBuffer, pdbBuffer-> szString); CListView :: AddDebugItem (tzBuffer, pdbBuffer-> dwProcessId);}} else {/ / wait failed m_dwResult = WAIT_ABANDONED;}}} _Finally {// release if (pdbBuffer) {UnmapViewOfFile (pdbBuffer);} _SafeCloseHandle (hMapping); _SafeCloseHandle (m_hReadyEvent); _SafeCloseHandle (hAckEvent); PostMessage (CMainWnd :: m_hWnd, WM_COMMAND, IDC_DEBUGTRACK, M_DWRESULT); // Return Result Return M_DWRESULT;}}
Of course, you can also choose sysinternals' debugview, more powerful (you can monitor remote monitoring), but no debugtrack is convenient. For in-depth analysis of OutputDebugstring, you can see this article: please check the article (E text): http://www.unixwiz.net/techtips/outputdebugstring.html