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.INC (Write to Console)

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

  • PBDLL DEBUG.INC (Write to Console)

    please post discussions here: http://www.powerbasic.com/support/pb...ead.php?t=4054

    a total of 5 posts:
    Code:
    post 1 - debug.inc include file to enable debug_print
    post 2 - ddt example using debug.inc
    **** new ****

    Code:
    posts 3, 4, and 5 don't require debug.inc
                              and are easier to impliment
    post 3 - dll version of debug.inc (you don't have to call
                                       debug_initialize or debug_terminate)
    post 4 - debugdll.inc include file for debugdll.dll
    post 5 - debugdll example
    
    debug.inc
    Code:
    '=============================================================================='
    '  powerbasic debugger.
    '  prints text to a console window, making debugging pb/dll easier
    '  please contact me at [email protected] if you have any questions
    '
    '  this is entered into public domain by greg engle 7-14-01
    '       debug_initialize - to start debug engine
    '       debug_terminate -  when you exit your program
    '       debug_print - prints a string to the console
    '       debug_print_lng - prints a long to the console
    '
    '==============================================================================
    'add these lines to your exe after "win32api.inc":
    '
    '%debugmode = %true
    '#include "debug.inc"
    
    declare sub debug_print(soutput$)
    declare sub debug_initialize_print(soutput$, conhwnd&)
    declare sub debug_terminate()
    declare sub debug_initialize()
    declare sub debug_print_lng(soutput as long)
    
    sub debug_print_lng(soutput as long)
        #if %debugmode      'you forgot to add %debugmode = %true before #include "debug.inc"
            debug_initialize_print format$(soutput), 0
        #endif
    end sub
    
    
    sub debug_print(soutput$)
        #if %debugmode
            debug_initialize_print soutput$, 0
        #endif
    end sub
    
    sub debug_initialize_print(soutput$, conhwnd&)
        #if %debugmode
            static hwnd&
            if conhwnd& > 0 then
                hwnd& = conhwnd&
            end if
            local szoutput as asciiz * 255
            szoutput = soutput$ & $crlf
            writeconsole hwnd&, szoutput, len(szoutput), %null, %null
        #endif
    end sub
    
    sub debug_terminate()
        #if %debugmode
            freeconsole
        #endif
    end sub
    
    sub debug_initialize()
        local conhwnd&
        #if %debugmode
            local szoutputt as asciiz * 255
            allocconsole 'create the console
            setconsoletitle "greg's powerbasic debugger"
            conhwnd& = getstdhandle(%std_output_handle)
            setconsoletextattribute conhwnd&, %foreground_red or _
                %foreground_green or %foreground_blue
             debug_initialize_print "greg's powerbasic debugger", conhwnd&
             debug_print "----------------"
             debug_print "
        #endif
    end sub
    ------------------
    -greg



    [this message has been edited by gregery d engle (edited july 15, 2001).]
    -Greg
    [email protected]
    MCP,MCSA,MCSE,MCSD

  • #2
    Sample DDT Version using DEBUG.INC

    Code:
    #COMPILE EXE
    #DIM ALL
    
    #INCLUDE "win32api.inc"
    %DEBUGMODE = %TRUE                  '* CHANGE TO %FALSE TO DISABLE DEBUG FUNCTIONS MUST BE BEFORE #INCLUDE "DEBUG.INC"
    #INCLUDE "debug.inc"                '* ADD AFTER %DEBUGMODE
    %BUTTON           = 100
    %COMBOBOX         = 105
    %LISTBOX          = 110
    CALLBACK FUNCTION DlgProc
        LOCAL CVal&
        LOCAL sBuffer$
        SELECT CASE CBMSG
            CASE %WM_COMMAND
                SELECT CASE CBCTL
                    CASE %LISTBOX
                        CONTROL SEND CBHNDL , CBCTL, %LB_GETCURSEL, 0,0 TO CVal&
                        IF CBCTLMSG=%LBN_SELCHANGE THEN
                            LISTBOX GET TEXT CBHNDL, CBCTL TO sBuffer$
                            DEBUG_PRINT "ListBox Item: " & sBuffer$             'What is the selected value?
                        END IF
                    CASE %COMBOBOX
                        CONTROL SEND CBHNDL , CBCTL, %CB_GETCURSEL, 0,0 TO CVal&
                        IF (CBCTLMSG=%CBN_SELCHANGE) OR  (CBCTLMSG=%CBN_EDITCHANGE) OR (CBCTLMSG=%CBN_EDITUPDATE) THEN
                            COMBOBOX GET TEXT CBHNDL, CBCTL TO sBuffer$
                            DEBUG_PRINT "COMBOBOX Item: " & sBuffer$            'What value did we select for the combobox?
                        END IF
                    CASE %BUTTON
                        IF CBCTLMSG=%BN_CLICKED THEN
                            DEBUG_PRINT "BUTTON1 Clicked"                         'did we click the button yet?
                        END IF
                END SELECT
            CASE ELSE
        END SELECT
    END FUNCTION
    
    FUNCTION PBMAIN
        DEBUG_INITIALIZE                    'call this at the begining of PBMAIN to initialize DEBUG_PRINT
        LOCAL Count&
        LOCAL hDlg&
        DEBUG_PRINT "Creating Dialog"
        DIALOG NEW 0, "Greg's DEBUG.INC DDT Example", 0, 0,  267,  100, _
                   %WS_POPUP OR %DS_MODALFRAME OR %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU OR %DS_CENTER, _
                   0, TO hDlg&
        CONTROL ADD "Button", hDlg&, %BUTTON,  "Button  1", 176, 17, 53, 15, _
                   %WS_CHILD OR %WS_VISIBLE OR %BS_PUSHBUTTON OR %WS_TABSTOP
        CONTROL ADD COMBOBOX, hDlg&,  %COMBOBOX, , 109, 10, 53, 52, _
                    %WS_CHILD OR %WS_VISIBLE OR %CBS_DROPDOWNLIST OR %CBS_SORT OR %WS_VSCROLL OR %CBS_NOINTEGRALHEIGHT OR %WS_TABSTOP, _
                    %WS_EX_CLIENTEDGE
        COMBOBOX ADD hDlg&, %COMBOBOX, "Combo 1"
        COMBOBOX ADD hDlg&, %COMBOBOX, "Combo 2"
        COMBOBOX ADD hDlg&, %COMBOBOX, "Combo 3"
        COMBOBOX ADD hDlg&, %COMBOBOX, "Combo 4"
        COMBOBOX ADD hDlg&, %COMBOBOX, "Combo 5"
        CONTROL ADD LISTBOX, hDlg&,  %LISTBOX, , 16, 15, 53, 59, _
                    %WS_CHILD OR %WS_VISIBLE OR %LBS_NOTIFY OR %LBS_SORT OR %LBS_NOINTEGRALHEIGHT OR %WS_VSCROLL OR %WS_TABSTOP, _
                    %WS_EX_CLIENTEDGE
        LISTBOX ADD hDlg&, %LISTBOX, "ListBox 1"
        LISTBOX ADD hDlg&, %LISTBOX, "ListBox 2"
        LISTBOX ADD hDlg&, %LISTBOX, "ListBox 3"
        LISTBOX ADD hDlg&, %LISTBOX, "ListBox 4"
        LISTBOX ADD hDlg&, %LISTBOX, "ListBox 5"
        
        DIALOG SHOW MODELESS hDlg& , CALL DlgProc
        DO
            DIALOG DOEVENTS TO Count&
        LOOP UNTIL Count&=0
        DEBUG_TERMINATE                 'Call this at the end of PBMAIN
    END FUNCTION

    ------------------
    -Greg



    [This message has been edited by Gregery D Engle (edited July 15, 2001).]
    -Greg
    [email protected]
    MCP,MCSA,MCSE,MCSD

    Comment


    • #3
      DEBUGDLL.DLL

      Code:
      '=============================================================================='
      '  PowerBasic Debugger. DLL Version
      '  Now puts Initialize and Terminate functions in %DLL_PROCESS_ATTACH and %DLL_PROCESS_DETACH
      '  You can use DEBUG_PRINT as soon as you include DEBUGDLL.INC
      '
      '  Prints Text to a Console Window, making Debugging PB/DLL easier
      '  Please contact me at [email protected] if you have any questions
      '
      '  This is entered into Public Domain by Greg Engle 7-14-01
      '       DEBUG_PRINT - PRINTS A STRING TO THE CONSOLE
      '       DEBUG_PRINT_LNG - PRINTS A LONG TO THE CONSOLE
      '
      '==============================================================================
      #COMPILE DLL "C:\WINNT\SYSTEM32\DEBUGDLL.DLL"
      #INCLUDE "WIN32API.INC"
      
      DECLARE FUNCTION DEBUG_PRINT(sOutput AS STRING) AS LONG
      DECLARE SUB DEBUG_INITIALIZE_PRINT(sOutput$, ConHwnd&)
      DECLARE SUB DEBUG_TERMINATE()
      DECLARE SUB DEBUG_INITIALIZE()
      DECLARE SUB DEBUG_INI()
      DECLARE FUNCTION DEBUG_PRINT_LNG(sOutput AS LONG) AS LONG
      
      FUNCTION DEBUG_PRINT_LNG(sOutput AS LONG) EXPORT AS LONG
              DEBUG_INITIALIZE_PRINT FORMAT$(sOutput), 0
      END FUNCTION
      
      
      FUNCTION DEBUG_PRINT(sOutput AS STRING) EXPORT AS LONG
              DEBUG_INITIALIZE_PRINT sOutput$, 0
      END FUNCTION
      
      SUB DEBUG_INITIALIZE_PRINT(sOutput$, ConHwnd&)
              STATIC Hwnd&
              IF ConHwnd& > 0 THEN
                  Hwnd& = ConHwnd&
              END IF
              LOCAL szOutput AS ASCIIZ * 255
              szOutput = sOutput$ & $CRLF
              WriteConsole Hwnd&, szOutput, LEN(szOutput), %NULL, %NULL
      END SUB
      
      SUB DEBUG_TERMINATE()
              FreeConsole
      END SUB
      
      SUB DEBUG_INI()
          LOCAL ConHwnd&
              LOCAL szOutputt AS ASCIIZ * 255
              AllocConsole 'create the console
              SetConsoleTitle "Greg's PowerBasic Debugger"
              ConHwnd& = GetStdHandle(%STD_OUTPUT_HANDLE)
              SetConsoleTextAttribute ConHwnd&, %FOREGROUND_RED OR _
                  %FOREGROUND_GREEN OR %FOREGROUND_BLUE
               DEBUG_INITIALIZE_PRINT "Greg's PowerBasic Debugger", ConHwnd&
               DEBUG_PRINT "----------------"
               DEBUG_PRINT ""
      END SUB
      
      SUB DEBUG_INITIALIZE()
          LOCAL ConHwnd&
          LOCAL szOutputt AS ASCIIZ * 255
          AllocConsole 'create the console
          SetConsoleTitle "Greg's PowerBasic Debugger"
          ConHwnd& = GetStdHandle(%STD_OUTPUT_HANDLE)
          SetConsoleTextAttribute ConHwnd&, %FOREGROUND_RED OR _
              %FOREGROUND_GREEN OR %FOREGROUND_BLUE
               DEBUG_INITIALIZE_PRINT "Greg's PowerBasic Debugger", ConHwnd&
               DEBUG_PRINT "----------------"
               DEBUG_PRINT ""
      END SUB
      
      FUNCTION LibMain(BYVAL hInstance   AS LONG, _
                       BYVAL fwdReason   AS LONG, _
                       BYVAL lpvReserved AS LONG) EXPORT AS LONG
      
          SELECT CASE fwdReason
      
              CASE %DLL_PROCESS_ATTACH
                  DEBUG_INITIALIZE
                  LibMain = 1
                  EXIT FUNCTION
      
              CASE %DLL_PROCESS_DETACH
                  LibMain = 1
                  EXIT FUNCTION
              CASE %DLL_THREAD_ATTACH
                 LibMain = 1
                 EXIT FUNCTION
             CASE %DLL_THREAD_DETACH
                 DEBUG_TERMINATE
                 LibMain = 1
                 EXIT FUNCTION
            END SELECT
      ------------------
      -Greg

      [This message has been edited by Gregery D Engle (edited July 15, 2001).]
      -Greg
      [email protected]
      MCP,MCSA,MCSE,MCSD

      Comment


      • #4
        DEBUGDLL.INC 'WRAPPER FOR DEBUGDLL.DLL

        Code:
        '%DEBUGMODE = 1                 'INCLUDE THESE LINES IN YOUR EXE
        '#INCLUDE "DEBUGDLL.INC"
        
        #IF %DEBUGMODE                  'NEED TO ADD %DEBUGMODE = 1 before #INCLUDE "DEBUGDLL.INC"
            DECLARE SUB DEBUG_PRINT LIB "DEBUGDLL.DLL" (sOutput$)
            DECLARE SUB DEBUG_PRINT_LNG LIB "DEBUGDLL.DLL" (sOutput&)
        #ELSE
            DECLARE SUB DEBUG_PRINT(sOutput$)
            DECLARE SUB DEBUG_PRINT_LNG(sOutput&)
            SUB DEBUG_PRINT(sOutput$)
            END SUB
            SUB DEBUG_PRINT_LNG(sOutput&)
            END SUB
        #ENDIF

        ------------------
        -Greg
        -Greg
        [email protected]
        MCP,MCSA,MCSE,MCSD

        Comment


        • #5
          EXAMPLE USING DEBUGDLL.DLL

          Code:
          #COMPILE EXE
          %DEBUGMODE = 1
          #INCLUDE "DEBUGDLL.INC"
          
          FUNCTION PBMAIN() AS LONG
              DEBUG_PRINT "Test"
              SLEEP 5000
          END FUNCTION
          ------------------
          -Greg

          [This message has been edited by Gregery D Engle (edited July 31, 2001).]
          -Greg
          [email protected]
          MCP,MCSA,MCSE,MCSD

          Comment

          Working...
          X