Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

PBDLL Debug Print to Console

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PBDLL Debug Print to Console

    '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.

    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
    Just call DEBUG "My ConString" to output and
    DEBUG $ConClose to close console.


    ------------------
Working...
X