Last active
May 27, 2025 22:44
-
-
Save ne1uno/f3c17113f3bf6b342c681b85a6271274 to your computer and use it in GitHub Desktop.
HowTo win32 OutputDebugString and example echo script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
send OutputDebugStringA for any listners like debugview++ | |
see also debugging tips, https://github.com/red/red/wiki/ [DOC]-Debugging | |
https://github.com/red/red/wiki/%5BDOC%5D-Debugging | |
; err: copy "" | |
dbgecho: %PATHTO/dbg-echo.red.exe | |
; probe call/error/shell rejoin [dbgecho " echo parse-trace"] err ;#"^@" added there | |
call rejoin [dbgecho " " form init-pos " echo parse-trace^@"] | |
; print [exists? dbgecho mold err] ;no error | |
dbgecho: %PATHTO/dbg-echo.red.exe | |
call rejoin [dbgecho " " form init-pos " echo parse-trace"] ;^@ | |
downside is every call followed by process terminated which could be filtered out | |
for compiled scripts easier to include or c&p dbg-view code | |
compile dbg-echo -t MSDos add to your path, this adds ^@ so no worries | |
Red [ | |
Title: "Debug Echo" | |
;Needs: 'console | |
;Needs: 'View | |
] | |
#system [ | |
#import [ | |
"kernel32.dll" stdcall [ | |
OutputDebugStringA: "OutputDebugStringA" [ | |
lpOutputString [int-ptr!] | |
return: [int-ptr!] | |
] | |
] | |
] | |
] | |
echo-debug: routine [ | |
txt [string!] | |
/local len cstr | |
][ | |
;this works, caller needs to add null | |
OutputDebugStringA as int-ptr! as c-string! string/rs-head txt | |
] | |
; probe mold | |
msg: system/script/args ;has extra blanks at end? should check quote behaviour | |
; SYSTEM/SCRIPT/ARGS is a string! | |
; SYSTEM/OPTIONS/ARGS is a block! | |
; SYSTEM/OPTIONS/PATH is a file! | |
; SYSTEM/OPTIONS/SCRIPT | |
; needs null byte to ensure proper termination? no rejoin in routine | |
; why isn't the cast checking for null term or adding it in routine? | |
echo-debug rejoin [trim msg #"^@"] ;ugly but works. should've added it above | |
; prevent exit when testing from CLI if you want to see if console shows | |
; forever [wait 9000] | |
comment { | |
not really ideal but might use | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
needed a real-time debug monitor that listens for win32 OutputDebugStringA r/s, c. | |
cGPT suggested https://github.com/CobaltFusion/DebugViewPP version 1.8, 1.5 still 32bit exe available for download | |
it's an opensource intellectual fork of the old ms debugview that stopped working around win7 | |
[another possibility, compile with -d to enable prints ] | |
( | |
https://github.com/red/red/wiki/[HOWTO]-VID-and-View-(GUI)-hints-and-tips dehexed links stopped redirecting? | |
https://github.com/red/red/wiki/%5BHOWTO%5D-VID-and-View-(GUI)-hints-and-tips#how-to-pass-data-to-second-window | |
) For debugging View apps, compile them with -d instead of -t Windows and run them from CMD. | |
That will redirect the prints to the standard output. | |
DebugView++ gives you filtering, logs and other niceties, though your script must be compiled | |
regular view with -t Windows seems to block console opening | |
so print & probe, print-line didn't work | |
had to compile -t MSDos, -r apparently important too | |
oddly enough, the gui sometimes opens a console which is why all the issues were closed? | |
tried to open a console manually but would then need pipes or something to communicate. | |
nothing is ever easy | |
hopefully someone can add missing pieces for other #OS, molding red-block!, red-string! etc. | |
Red [ | |
Title: "win32 debugview caller" | |
Author: "ne1 cGPT4o" | |
File: %.reds | |
Version: 0.1.0 | |
Date: "Sun 20250518 PM 14:10 " | |
; Needs: 'View | |
;icon: %test.ico | |
] | |
ctx: context [ ; copy this into your script or change Red/System header & #include before and above use | |
#system [ | |
#import [ | |
"kernel32.dll" stdcall [ | |
OutputDebugStringA: "OutputDebugStringA" [ | |
lpOutputString [int-ptr!] | |
return: [int-ptr!] | |
] | |
] | |
] | |
_sys-debug: func [ "for use inside #system to send string to debugviewer" | |
rtxt [c-string!] | |
][ | |
OutputDebugStringA as int-ptr! rtxt | |
] | |
;note: chicken egg, can't use before defined or included above | |
_sys-debug "red-lang inside #system " ;to debugview++ | |
] ; e #system | |
log-debug: routine [ "use from red code to send string to debugviewer" | |
txt [string!] | |
;/local s | |
][ | |
OutputDebugStringA as int-ptr! as c-string! string/rs-head txt | |
] | |
] ; e ctx | |
;note ^@ null \0 added, the cast to c-string! may assume you added null, this should've be done above... | |
probe ctx/log-debug "red-lang debug fired^@" ;debugview++ adds time, tags line w/exe name, adds newline ^/ | |
forever [wait 9000] | |
; exe console apps exit very rudely after doing their business | |
; they don't share a console so you can't start from cmd to solve the problem | |
; maybe there's a cleaner way but nobody else seems to notice the problem | |
halt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment