Announcement

Collapse

Maintenance

The forum could be offline for 30-60 minutes in the very near future for maintenance (said 3pm Pacific). I was behind on getting this notice. I do apologize.
See more
See less

PB -> VB Callback error

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

  • PB -> VB Callback error

    This runs fine but it seems to run my vb code synchronously and
    once it makes a callback it will briefly comeback to life and
    then lock back up.

    '--PB CODE ---'

    Code:
    #COMPILE DLL "c:\windows\system\PSC.dll"
    #DIM ALL
    %True  = -1
    %False = 0
    
    'DECLARE SUB Display(BYVAL sData AS STRING)
    DECLARE FUNCTION test() AS LONG
    'DECLARE FUNCTION GetPSC(BYVAL Address AS LONG PTR, COMMPORT AS LONG) AS LONG
    DECLARE FUNCTION PBMAIN() AS LONG
    
    FUNCTION GetPSC(BYVAL Address AS LONG PTR) EXPORT AS LONG
      'CALL DWORD Address
      DIM hComm   AS LONG
      DIM Echo    AS LONG
      DIM Qty     AS LONG
      DIM Stuf    AS STRING
      DIM MyInput AS STRING
      DIM CommPort AS LONG
      commPort = 1
    '
        DIM NewString AS STRING PTR
    '    NewString = glCode
        
     DIM Counter AS LONG
    '#DEBUG PRINT "COM" & STR$(COMMPORT)
      COMM OPEN "COM" & LTRIM$(STR$(COMMPORT)) AS #hComm
      IF ERRCLEAR THEN EXIT FUNCTION          'Exit if port cannot be opened
    
      COMM SET #hComm, BAUD     = 9600        '1200 baud
      COMM SET #hComm, BYTE     = 8           '8 bits
      COMM SET #hComm, PARITY   = %False      'No parity
      COMM SET #hComm, STOP     = 0           '1 stop bit
      COMM SET #hComm, TXBUFFER = 1024        '1k transmit buffer
      COMM SET #hComm, RXBUFFER = 1024        '1k receive buffer
     ' counter = 1
     DO
        Qty = COMM(#hComm, RXQUE)
    
        IF ISTRUE Qty THEN
           COMM RECV #hComm, Qty, Stuf
    '       @NewString = Stuf
           OPEN "C:\hook.id" FOR OUTPUT AS #2
           PRINT #2, Stuf
           CLOSE #2
           CALL DWORD Address
        END IF
     LOOP
    
    Terminate:
      COMM CLOSE #hComm                       'close the comm port and exit
      EXIT FUNCTION
    
    END FUNCTION
    
    FUNCTION PBMAIN() AS LONG
    DIM a&
        a& = GetPSC(CODEPTR(test))
    END FUNCTION
    
    FUNCTION test() AS LONG
        MSGBOX "hi" 'glcode$
    END FUNCTION
    '---VB CODE ---'

    Code:
    '---- MAIN.BAS ----'
    Option Explicit
    Public Declare Function GETPSC Lib "PSC.DLL" (ByVal funcptr As Long) As Long
    
    Sub main()
    FrmMain.Show
    End Sub
    
    Sub TestSub()
    MsgBox "blah blah blah yoyo"
    End Sub
    
    '---- FRMMAIN.FRM -----'
    Private Sub Command1_Click()
    GETPSC AddressOf TestSub
    End Sub
    Thanks,



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

  • #2
    Sounds like it's working the way I'd expect it to work. The question is, how do you expect it to work?

    ------------------
    Tom Hanlin
    PowerBASIC Staff

    Comment


    • #3
      Tom,

      It seems to stop execution of my VB program when I execute this and
      then it returns execution when I call dword.

      This program is being used for a barcode scanner.

      Thanks,

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

      Comment


      • #4
        If you want to run the VB code at the same time as the PB code, you
        will need to use a different approach-- multithreading, perhaps,
        although VB has limited support for that (see the FAQ "forum").

        Depending on what you have in mind, you might find it effective
        simply to maintain a message pump in your DO..LOOP, which is currently
        blocking the flow of messages to your program.

        The loop is also going to eat a lot of CPU time doing nothing in
        particular. You might want to look into the WaitForSingleObject API
        call and related functions.

        ------------------
        Tom Hanlin
        PowerBASIC Staff

        Comment

        Working...
        X