'I found several DebugPrint on forum and most of them uses 'separated subs to control console window.
'This is another Debug Print, but uses only one procedure to 'initialize/print/close console.
Just call DEBUG "My ConString" to output and
DEBUG $ConClose to close console.
------------------
'This is another Debug Print, but uses only one procedure to 'initialize/print/close console.
Code:
'=============================================== ' Debug Print Module for PowerBasic DLL ' All in One '=============================================== #COMPILE EXE #INCLUDE "win32api.inc" DECLARE SUB DEBUG (st$) $ConClose = "$CON:CLOSE" FUNCTION PBMAIN () Debug "Console Opened" MSGBOX "Output string to console..." Debug "Simple DebugPrint in PBDLL6!" MSGBOX "Press OK To Close Console" ' we send magic code that close console. Debug $ConClose MSGBOX "Console Closed" MSGBOX "Press OK to reopen console" Debug "Console Reopened" MSGBOX "Done" Debug $ConClose END FUNCTION SUB DEBUG (st$) STATIC Hwnd& LOCAL szConsole AS ASCIIZ * 255 IF Hwnd& = 0 THEN AllocConsole SetConsoleTitle "PBDLL Console" Hwnd& = GetStdHandle(%STD_OUTPUT_HANDLE) SetConsoleTextAttribute Hwnd&, %FOREGROUND_RED OR _ %FOREGROUND_GREEN OR _ %FOREGROUND_BLUE END IF IF Hwnd& > 0 THEN ' a magic word that close console IF st$=$ConClose THEN FreeConsole Hwnd& = 0 EXIT SUB END IF szConsole = st$ & $CRLF WriteConsole Hwnd&,szConsole,LEN(szConsole),%NULL,%NULL END IF END SUB
DEBUG $ConClose to close console.
------------------