title: Capturing OutputDebugString() calls on a server written in Delphi
body: <p>I have a server written in Delphi that I would like to add a debug logger to so it can log messages passed to Windows.OutputDebugString() while it is deployed, so clients can send me the log when there are issues. In the end, I want functionality similar to <a href="https://docs.microsoft.com/en-us/sysinternals/downloads/debugview" rel="nofollow noreferrer">DebugView</a>, but built into the server program itself.</p>
  
  <p>I understand how the OutputDebugString works by writing to a shared memory file and using system wide events to synchronize the program and its debugger, and I have <a href="http://www.michaelfcollins3.me/blog/2013/06/01/understanding-outputdebugstring.html" rel="nofollow noreferrer">found solutions in C#</a> and <a href="http://www.codeproject.com/Articles/23776/Mechanism-of-OutputDebugString" rel="nofollow noreferrer">C++</a>, but have yet to be able to translate those solutions to Delphi.</p>
  
  <p>My largest problem is not knowing how to interact with the DBWIN_BUFFER_READY and DBWIN_DATA_READY synchronization events with Delphi, or how to reference the specific memory mapped file "DBWIN_BUFFER" that OutputDebugString writes to.</p>
  
  <p>Additionally I have found solutions that implement their own method call instead of Windows.OutputDebugString(), but the program already has hundreds of calls, both in the code we have written and third-party modules we have added in, so these are not an option.</p>