How to view output of OutputDebugString?
Asked Answered
J

5

14

I want to use OutputDebugString() in my application and then have the option to show it in a separate viewer when the application is deployed in the field.

That is to say, I don't want to have to change a flag and rebuild my .exe to turn debugging on and off.

Googling around, it seems like DebugView should handle that, but neither it, nor TraceTool show any output from this code.

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.FormCreate(Sender: TObject);
begin
   OutputDebugString(PChar('Hello, wurld'));
end;

end.

I have read the documentation, to no avail, and see that others have had similar problems, but have not posted a solution.

Is there a solution?

Jeaniejeanine answered 27/6, 2012 at 2:4 Comment(8)
GExperts has a debug viewer and a unit you add to your app that will do this for you, even in XE2 starter. See the DebugIntf unit and the GExpertsDebugWindow.exe application that it includes. These work under XE2 Starter (and pretty much all other versions of Delphi).Shondrashone
+1 I will check out gexperts.org/tour/index.html?debug_window.htmlJeaniejeanine
If you posted that as an answer, I would probably award it, despite the sterling help from @RRUZ This is the solution that I will be going with - FOR EXE2 STARTER edition. It seems to be the only solution that works both in and out of the IDE. For other editions, I might prefer the greate roptions of TraceToool, but Gexperts looks more than fine for my needs.Jeaniejeanine
That's why I wrote this DbWinUnit: bo.codeplex.com/SourceControl/changeset/view/78543#1494219 it allows you to write both using OutputDebugString (that is catched by the currently running debugger) and uses the DBWIN protocol so that DebugView can also catch the output.Mortarboard
have you tried this - codeproject.com/Articles/23776/Mechanism-of-OutputDebugStringTarbox
Jeroen (+1), do you know how how it would behave with Delphi XE2 Starter? That does not have an event log window. If I run in the IDE would output then go to the external Debug Viewer? Or would it go to the IDE which has no window for me to view it?Jeaniejeanine
I remember SysInternals DebugView described, that depending on Windows version and executing subsystems, there wer 3 different OutputDebugString routines with its quirks, and loggers had its quirks too. There was recommendation to end each outputting string with #13#10 (\r\n)Manometer
peganza.com/delphi-and-outputdebugstring.htmlBlockhead
S
9

GExperts has a debug viewer and a unit you add to your application that will do this for you, even in XE2 Starter. See the DebugIntf unit and the GExpertsDebugWindow.exe application that it includes. These work under XE2 Starter (and pretty much all other versions of Delphi).

GExperts also includes tons of other IDE and editor enhancements that are great, and of course they've been around forever, so they're pretty solid tools.

Shondrashone answered 27/6, 2012 at 11:0 Comment(4)
It doesn't run on a PC which has never had Delphi installed (can't find RTL60.BPL). I have posted to the GExperts mailing list, but so mfar had no reply.Jeaniejeanine
It's built with runtime packages. If the version number in the BPL you give isn't a typo (I think it should be 160, not 60), you have a very early version installed (60 was around Delphi 6, IIRC). If it is 160, you can find that in your Windows\System32 folder, and put it in the same folder as you put the debug viewer executable. It's one of Delphi's distributable runtime libraries, so you're allowed to ship it with the app. You'll need VCL160 and VCLX160, too.Shondrashone
Oops, it was indeed 160, not 60. I had already copied that BPL, but did not know to copy the other two. That works nicely. Thank you, as always, for your excellent help.Jeaniejeanine
Careful, GExpers is known to crash the IDE: quality.embarcadero.com/browse/RSP-34374Blockhead
J
30

The DebugView tool works fine; only be sure to launch your application directly (without the Delphi IDE or another debugger attached).

Anyway, the natural way to view the OutputDebugString output for a Delphi application is to use the Delphi IDE and the Event Log Window.

Enter image description here

Enter image description here

Jugendstil answered 27/6, 2012 at 2:16 Comment(11)
+1 can you confirm that XE2 starter edition doesn't have an event log viewer? embarcadero.com/products/delphi/delphi-feature-matrix seems to indicate so. Presumably, then, I can't view my output from the IDE, but only when I run it stand-alone?Jeaniejeanine
I can't believe which the Event Log Windows isn't part of the Delphi Starter edition :(Jugendstil
But it looks that way in the feature matix, right? And I can't find it on the menu ...Jeaniejeanine
Yes, it seems a Delphi Starter limitation.Jugendstil
Hmmm, I do understand that Embarcadero had to cut features for the starter (else no one would have bought anything else). But if the IDE doesn't handle it, couldn't they have made it so that outher programs, such as DebugView could handle OutputDebugString() while I am steeping through my my app in the IDE?Jeaniejeanine
I understand your frustration, Are you tried the Ken White suggestion about the GExperts plugin?Jugendstil
@RRUZ: I know a cool tool that you can use to fix the color scheme of your IDE. Interested? ;)Invitation
One minor downside of the built-in Event Viewer is that it has no way to properly show a message with built-in line breaks--it folds it into a single line with "funny characters" in place of line breaks. Delphi 7 IDE (yes, I know it's year 2014 but still).Joshia
@Jeaniejeanine I highly suspect that Starter-edition IDE actually handles (receives) it, but just don't show it.Sonya
@Mawg, So does it work or does it not work? Why did you accept the other answer as answer instead of this?Isometric
OutputDebugString output does not seem to appear in Event Log window.Rupert
S
9

GExperts has a debug viewer and a unit you add to your application that will do this for you, even in XE2 Starter. See the DebugIntf unit and the GExpertsDebugWindow.exe application that it includes. These work under XE2 Starter (and pretty much all other versions of Delphi).

GExperts also includes tons of other IDE and editor enhancements that are great, and of course they've been around forever, so they're pretty solid tools.

Shondrashone answered 27/6, 2012 at 11:0 Comment(4)
It doesn't run on a PC which has never had Delphi installed (can't find RTL60.BPL). I have posted to the GExperts mailing list, but so mfar had no reply.Jeaniejeanine
It's built with runtime packages. If the version number in the BPL you give isn't a typo (I think it should be 160, not 60), you have a very early version installed (60 was around Delphi 6, IIRC). If it is 160, you can find that in your Windows\System32 folder, and put it in the same folder as you put the debug viewer executable. It's one of Delphi's distributable runtime libraries, so you're allowed to ship it with the app. You'll need VCL160 and VCLX160, too.Shondrashone
Oops, it was indeed 160, not 60. I had already copied that BPL, but did not know to copy the other two. That works nicely. Thank you, as always, for your excellent help.Jeaniejeanine
Careful, GExpers is known to crash the IDE: quality.embarcadero.com/browse/RSP-34374Blockhead
S
5

CnWizards contains a tool, CnDebugViewer.exe, which can capture OutputDebugString (should be run as administrator in Windows 7).

Not like DbgView, CnDebugViewer can create separated tabs for different applications.

CnPack contains an unit, CnDebug.pas. Using this unit, you can trace typed objects, collections, exceptions, memdump, etc. With CnDebug.pas, you also can set whether to autostart CnDebugViewer, whether dump to file while sending debug messages, etc.

Shebeen answered 27/6, 2012 at 6:11 Comment(0)
K
4

One problem with using OutputDebugString is that other programs may also be using it, cluttering your log: Debugging OutputDebugString calls in Delphi.

You could use CodeSite Express, which we've been very happy with in day-to-day use: http://www.raize.com/devtools/codesite/Default.asp.

Karajan answered 27/6, 2012 at 12:23 Comment(3)
That's only a problem if you're using a tool that intentionally collects messages from other programs and then offers no way to filter them. Plain old debuggers won't have that problem because OutputDebugString usually only sends messages to the single program debugging it. The SysInternals tool uses a different, non-standard technique for collecting messages without becoming a debugger for all processes. But it also allows filtering. So there's really no problem at all.Tmesis
Code Site does not appear to be free :-(Jeaniejeanine
CS Express is included in XE2 & XE3. I've been using the full version for years; outstanding tool, much more useful than it may appear at first glance.Internal
R
2

In my version of XE5, I had to enable the "Output Messages" option under:

Tools > Options > Debugger Options > Event Log

I don't recall disabling it.

Reputable answered 11/7, 2014 at 22:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.