Have you ever noticed that your program is running slowly because you have waaaaaay too many calls to OutputDebugString (ODS) ?
What’s worse, is when it’s a complete waste, because there is no program running to benefit from ODS calls.
Here’s a programmatic way to detect if a viewer is running
P.S. my favorite ODS viewer is DebugView++ GitHub - CobaltFusion/DebugViewPP: DebugView++, collects, views, filters your application logs, and highlights information that is important to you!
The following code is based on VB code written by Carl Barnes.
Carl based his work on info found here: Understanding Win32 "OutputDebugString"
PROGRAM
INCLUDE('Windows.inc'),ONCE
MAP
OutputDebugStringNotReady(),LONG
MODULE('Standard Windows APIs')
OpenEvent (DWORD InDesiredAccess, BOOL InInheritHandle, |
*CSTRING InName),HANDLE,RAW,PASCAL,NAME('OpenEventA')
!already declared in Windows.inc! GetLastError (),DWORD,PASCAL
!already declared in Windows.inc! CloseHandle (HANDLE InObject),BOOL,PASCAL
END
END
CODE
MESSAGE('An OutputDebugString View is ['& |
CHOOSE( OutputDebugStringNotReady()=0, |
'Running', 'NOT Running') &']')
OutputDebugStringNotReady PROCEDURE()!,LONG
!Ported from VB6 Code written by *Carl Barnes*
!PSS: OutputDebugString is expensive requiring a switch to kernel mode to access event, mutex and MMF. See
! http://www.unixwiz.net/techtips/outputdebugstring.html
hObject HANDLE,AUTO
SYNCHRONIZE DWORD(100000h) ! 10 0000
szEventName CSTRING('DBWIN_BUFFER_READY') !case sensitive
RetError LONG,AUTO
CODE
hObject = OpenEvent(SYNCHRONIZE, FALSE, szEventName)
IF hObject <> 0
CloseHandle(hObject)
RetError = 0 !We are ready
ELSE
RetError = GetLastError()
! probably 2 = File Not Found,
! i.e. the Event name does not exist because there is no debugger
IF RetError = 0
RetError = -1 ! no handle and no error, then say -1
END
END
RETURN RetError



