| View previous topic :: View next topic |
| Author |
Message |
procyon
Joined: 10 Feb 2005 Posts: 14 Location: Tallinn, Estonia
|
Posted: Thu Feb 10, 2005 6:54 pm Post subject: OutputDebugString implementation |
|
|
| I use OutputDebugString for most of my programming tasks, and I'm sure AutoHotkey would also benefit from this easy and convenient debugging feature. |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Fri Feb 11, 2005 7:31 am Post subject: |
|
|
Btw. Welcome procyon. Nice to know that someone from the Baltics is arround.  |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10474
|
Posted: Fri Feb 11, 2005 11:53 am Post subject: Re: OutputDebugString implementation |
|
|
| procyon wrote: | | I use OutputDebugString for most of my programming tasks, and I'm sure AutoHotkey would also benefit from this easy and convenient debugging feature. | Do you mean having such strings appear in the script's main window or some similar window?
In case it helps, you can put "breakpoints" into a script this way:
ListLines ; Or ListVars (to show the contents of all variables)
pause
When the script reaches a breakpoint, it will display the info and then wait for you to unpause it. |
|
| Back to top |
|
 |
procyon
Joined: 10 Feb 2005 Posts: 14 Location: Tallinn, Estonia
|
Posted: Fri Feb 11, 2005 12:31 pm Post subject: |
|
|
I use a program called DebugView from Sysinternals - http://www.sysinternals.com/ntw2k/freeware/debugview.shtml that enables me to view debug output from my programs. By inserting OutputDebugString("some_explaining_text_and_values_of_variables") to key locations I can easily find out the cause of problem, if something went wrong.
I could of course use messageboxes or in this case breakpoints in scripts, but this would require my interaction while the script is running. With OutputDebugString I can let the script/program run as normal, and determine what went wrong afterwards. Of course I could also write a logfile to disk, but IMHO DebugView is so much more convenient.
And implementing this feature in AutoHotkey should be very easy.
A command called OutputDebugString with one string parameter, that would just call void OutputDebugString(LPCTSTR lpOutputString); with the same parameter.
Edit:
I tested ListVariables a bit, but it has some annoying side effects:
1) AutoHotkey window is activated every time
2) No history of values of variables, only most recent values
Edit2:
Just in case I was a bit unclear - void OutputDebugString(LPCTSTR lpOutputString); is a standard windows API call exported by kernel32.dll |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Fri Feb 11, 2005 3:41 pm Post subject: |
|
|
| Quote: | | A command called OutputDebugString with one string parameter, that would just call void OutputDebugString(LPCTSTR lpOutputString); with the same parameter. |
That seems easy enough; if you know enough C++, you can just make the command yourself and recompile AutoHotkey. I don't think anyone else would use this feature anyway. |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Fri Feb 11, 2005 3:58 pm Post subject: |
|
|
I would use it. It's a great idea, although I would not put it on high priority. If Chris could put it on his to-do/wish list, it would be great. _________________ Ciao
toralf  |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Fri Feb 11, 2005 4:01 pm Post subject: |
|
|
| The nature of it restricts it's usage to those who have the appropriate debugging utilities, though. I imagine this is restricted to those who are heavy coders in a different language already, which, I'd guess, is a relatively small percentage of the AHK community. |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Fri Feb 11, 2005 4:08 pm Post subject: |
|
|
As procyon posted: the tool is freeware. So no problem for anyone to get it. I assume that nearly every AHK user is already useing command line tools. So why not get that tool too if he wants to have a benifit from that comand? _________________ Ciao
toralf  |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Fri Feb 11, 2005 4:56 pm Post subject: |
|
|
Because up 'till now, AHK has stayed distant from other software of any kind, and I think it helps it's image a lot. It would be kind of strange to include a link to a foreign debugger on the main page, and to find out that it is intimately integrated with AutoHotkey. Call it "purity," call it "cleanness," call it whatever you want, but I think AHK should stand alone.
Of course outside software helps; I couldn't imagine using AHK without Winspector Spy, PSPad, or the countless command line tools I have in PATH. But the point is that they are optional, and use AHK features that are unobtrusive and not specialized like this would be.
As a last note, the size of AHK scripts/executables already surprises some; we should try to avoid adding more commands "on-demand" or just as a novelty. Like I said, if it's just a few lines, recompile it yourself. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10474
|
Posted: Fri Feb 11, 2005 7:07 pm Post subject: |
|
|
| toralf wrote: | | I would use it. It's a great idea, although I would not put it on high priority. | I don't have a concrete idea of exactly how it would work or what it would do. My impression is that you would store the store the output of OutputDebugString in memory. Later (upon selecting something from the main menu or tray menu, perhaps), the script could pop up a window containing the debug log for that session. Is this what you had in mind? |
|
| Back to top |
|
 |
Mats Guest
|
Posted: Fri Feb 11, 2005 8:25 pm Post subject: |
|
|
Not quite. OutputDebugString is a simple Windows-API function (takes only a string as parameter) and that's all. There is no need to buffer anything. Another program (like the one from sysinternals, but there are dozens of other tools that do this) can hook into windows to receive the string. If no such program is running, no one will ever see the messages. Otherwise you see the live output just like printing to a console window.
It is a great help for debugging scripts, because you can leave your debug messages in the production code and only start the DebugString-Viewer when you want to see what's going on. No need for debug-MsgBoxes anymore!
Again: There is no penalty for using OutputDebugString without a Viewer/Debugger. And OutputDebugString is no third party tool - it's part of windows! |
|
| Back to top |
|
 |
procyon
Joined: 10 Feb 2005 Posts: 14 Location: Tallinn, Estonia
|
Posted: Fri Feb 11, 2005 8:39 pm Post subject: |
|
|
This is how OutputDebugString API call works:
when a program calls it with some string as a parameter:
OutputDebugString("some text to output");
the windows kernel determines if there is a debugger attached to the process, if so the debugger gets the pointer to the string to do whatever it feels appropriate (DebugView adds it to its display, some debuggers pop-up a message box etc.) If no debuggers are present, then it does nothing.
An example:
| Code: |
#include <windows.h>
int main(void)
{
OutputDebugString("test string");
return 0;
}
|
This program would just exit if no debugger is present.
If you run it with for example DebugView present, then you see "test string" in DebugView's window. An example of how DebugView's output looks like, is on the page I gave the link to earlier.
Of course I admit, that not many people besides programmers know about debugging etc. So my suggestion would be - a command similar to ListVariables, but - it should let user specify some text to output, and the output would be shown on one of the windows accessible from "View" menu of AHK. |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Fri Feb 11, 2005 8:54 pm Post subject: |
|
|
| Sorry. I was uncertain of the exact nature of it; I think this sounds great. |
|
| Back to top |
|
 |
JSLover
Joined: 20 Dec 2004 Posts: 542 Location: LooseChange911.com... the WTC attacks were done by the US Gov't... the official story is a lie...
|
Posted: Sat Feb 12, 2005 12:19 am Post subject: |
|
|
| Chris wrote: | | I don't have a concrete idea of exactly how it would work or what it would do. |
...as other people have said, it's a raw Win API call, like BlockInput (except perhaps, unlike BlockInput, this one takes one parameter...I don't know, maybe the BlockInput API does take a param?). Basically if you implement my WinAPI command, this would automatically be implemented too.
| Chris wrote: | | Do you mean having such strings appear in the script's main window or some similar window? |
...he didn't mean that, but giving the AHK main window the DebugView functionality would be good, a new menu item "Debug messages.....Ctrl+D" & command ListDebug (or ViewDebug). Debugging with MsgBox's is clunky & sometimes changes the outcome, the delay provided by the box gives some things time to happen, but without the MsgBox, that same thing would fail. I recommend both, the OutputDebugString command & the AHK DebugView. Perhaps a separate .exe that hooks into all existing & newly run AHK processes & adds that menu item, so each script isn't operating as it's own DebugView. One .exe would catch the debug messages & send it to any AHK windows that request it & thus be off while the other .exe isn't running. My 1st idea was for the new .exe to add the menu item, but it could exist & start the program if it's not running, any AHK could start it, but it would only run once & work for all AHK's. Perhaps while running tho, it would add a menu item "Close Debugger" to stop that process. _________________
Home • Click image! • Blog |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Sat Feb 12, 2005 1:53 am Post subject: |
|
|
I have debugging code I use with pclip to output errors to the familiar console; just my two cents.  |
|
| Back to top |
|
 |
|