[RESOLVED] Robust Debug/Console Window for Printing
I'm in a situation where I'd like a robust Immediate window (just for printing out things during runtime). I'm working on something that's often crashing my IDE. (I'd go into what that is, but it's not necessary for my question.)
So, when the IDE crashes, I lose anything I've printed to the Immediate window. I've been thinking about a print to some console window. The only thing that comes to mind is writing a second program that hooks its window and listens for WM_COPYDATA. Also, that window could have some very unique title so it could be found by other applications.
Then, in my IDE crashing development application, I could find that unique top-level title, and send messages to it with WM_COPYDATA.
I haven't started, but I'll probably test that concept.
I'm just wondering if I'm overlooking something easier. I'm in a situation where I need to put in Debug.Print statement (or something similar), and not lose it if/when the IDE crashes.
Yeah, I know I could append to a file, but I'd like something that's more immediately visible to me.
Thanks,
Elroy
Re: Robust Debug/Console Window for Printing
I use OutputDebugString() API function in these situations, which sends the output to this external debugger(No installation needed, just unzip). The function wrapper below would cover both printing in the IDE and the EXE:
VB Code:
Public Declare Sub OutputDebugString Lib "kernel32" Alias "OutputDebugStringA" (ByVal lpOutputString As String)
Public Sub DebugPrint(ByRef s As String)
Debug.Print s
OutputDebugString s & vbCrLf
End Sub
The only drawback is that it doesn't support Print syntax, so you can't use ",;"
Re: Robust Debug/Console Window for Printing
Also, if you have VC6 installed, there is an easy way to find the cause of a GPF in a compiled VB6 app, see here for details.
Re: Robust Debug/Console Window for Printing
I'm using the same DebugPrint as qvb6 suggested w/ the added twist that actual debug output is activated w/ an environment "switch" variable like this
thinBasic Code:
Public Sub OutputDebugString(sText As String)
Static lLogging As Long
If lLogging = 0 Then
lLogging = IIf(Val(Environ$("_MY_PLUGIN_ALLOW_DEBUG")) <> 0, 1, -1)
End If
If lLogging > 0 Then
Call APIOutputDebugString(sText)
End If
End Sub
Using DbgView.exe for the actual message viewer.
cheers,
</wqw>
Re: Robust Debug/Console Window for Printing
Hmmm, well, I took a look at the OutputDebugString option (in conjunction with the DebugView program), and that's not a bad option at all. However, and I'm not sure why, but I seem to have a couple of other programs running that are somewhat regularly posting debug information, and it gets woven in with my debug messages. I should probably look into those other program.
But anyway, I decided to write my own, and just finished it. Personally, I think it's pretty cool, so I'm going to post it in the CodeBank.
Thanks to all for the consideration on this. :)
Elroy
Re: [RESOLVED] Robust Debug/Console Window for Printing
Elroy, you can implement the IVBPrint interface in a class and create a predeclared instance of that one which wraps the OutputDebugString function. In this case you can use the code like cSomeClass.Print aa; b, qwq;;; etc. which is very similar to Debug.Print.
Alternatively, the immediate pane supports the IVBPrint interface and you can intercept and route the messages to file/pipe/etc.
Re: [RESOLVED] Robust Debug/Console Window for Printing
Great idea Trick. I see where Eduardo has used it a couple of times. When I revisit my Persistent Debug Print Window program, I'll definitely slip that in.