Announcement

Collapse
No announcement yet.

Urgent - Response needed Now!

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

  • Urgent - Response needed Now!

    I have a DLL created with PBDLL 6.
    I am using VB6 to access functions in the DLL.
    If have the following in the DLL.

    DECLARE FUNCTION AppCallBack(EventID AS LONG, TheData AS LONG) AS LONG

    FUNCTION WITSSetEventHandler(BYVAL ConnHandle AS LONG, BYVAL CallBackAddress AS DWORD) EXPORT AS LONG
    LOCAL Answer AS LONG
    LOCAL EventId AS LONG
    LOCAL Msg AS STRING

    Msg = "This is a test"
    EventId = 2

    CALL DWORD CallBackAddress USING AppCallBack(EventId, STRPTR(Msg)) TO Answer


    In VB I have:
    Answer = WITSSETEVENTHANDLER(1, AddressOf WITSCallBack)

    Public Function WITSCallBack(EventId As Long, msg As String) As Long

    MsgBox "Message received" <= This message box comes up

    MsgBox "EventID = " + Str$(EventId) <= This message box comes up with correct value

    MsgBox msg, , Str$(EventId) <= This message box displays ???????

    WITSCallBack = 0

    End Function

    I have tried every variation I can think of.
    Pass as a string
    pass as an asciiz
    pass as a dword
    pass as a long
    pass byval
    pass byref

    The closest I can get is to declare the message as a long
    and then pass vb a pointer to the string.
    It does not display the message but it also does not GPF.

    I need an answer really quick.
    Any help would be tremendously appreciated.

    Thanks
    Ben Clark
    [email protected]



    ------------------
    Ben Clark
    [email protected]
    If at first you don't succeed, destroy all evidence that you tried.

  • #2
    could you show your VB declaration for WITSSETEVENTHANDLER

    Thanks,
    Don

    ------------------
    www.basicguru.com/dickinson
    Don Dickinson
    www.greatwebdivide.com

    Comment


    • #3
      > Public Function WITSCallBack(EventId As Long, msg As String) As Long

      Probably I'm wrong, but you need ByVal msg As String

      BTW, do you have Microsoft documentation with explanation how to call VB functions from external programs ?
      I - not. If you also, look a sample, which I posted some minutes ago.

      [This message has been edited by Semen Matusovski (edited February 01, 2001).]

      Comment


      • #4
        Use this Visual Basic code, and adjust PBCode accordingly
        Code:
        Declare Function lstrcpyA Lib "Kernel32" (Byval lpString1 As Any, ByRef lpString2 As Any) As  Long
          
        Public Function WITSCallBack(EventId as Long,ptrMsg As Long) As Long
        Dim PBMsg$,rc&,pEnd&
           
            PBMsg$ = Space(2049)
            rc& = lstrcpyA(PBMsg$,ptrMsg)
            pEnd& = InStr(PBMsg$, Chr$(0))
            If (pEnd& > 0) Then PBMsg$ = Left$(PBMsg$,pEnd& - 1)
          
            MsgBox "Message received" 
            MsgBox "EventID = " + Str$(EventId)
            MsgBox PBmsg$, , Str$(EventId)
           
            WITSCallBack = 0
        End Function



        [This message has been edited by Fred Oxenby (edited February 01, 2001).]
        Fred
        mailto:[email protected][email protected]</A>
        http://www.oxenby.se

        Comment


        • #5
          Originally posted by Don Dickinson:
          could you show your VB declaration for WITSSETEVENTHANDLER

          Thanks,
          Don

          It is:
          Public Declare Function WITSSETEVENTHANDLER Lib "eWITS.DLL" (ByVal ConnHandle As Long, ByVal CallBackAddress As Long) As Long




          ------------------
          Ben Clark
          [email protected]
          If at first you don't succeed, destroy all evidence that you tried.

          Comment


          • #6
            I tried your suggestion.
            It only show giberish.

            Originally posted by Fred Oxenby:
            Use this Visual Basic code, and adjust PBCode accordingly
            Code:
            Declare Function lstrcpyA Lib "Kernel32" (Byval lpString1 As Any, ByRef lpString2 As Any) As  Long
              
            Public Function WITSCallBack(EventId as Long,ptrMsg As Long) As Long
            Dim PBMsg$,rc&,pEnd&
               
                PBMsg$ = Space(2049)
                rc& = lstrcpyA(PBMsg$,ptrMsg)
                pEnd& = InStr(PBMsg$, Chr$(0))
                If (pEnd& > 0) Then PBMsg$ = Left$(PBMsg$,pEnd& - 1)
              
                MsgBox "Message received" 
                MsgBox "EventID = " + Str$(EventId)
                MsgBox PBmsg$, , Str$(EventId)
               
                WITSCallBack = 0
            End Function

            [This message has been edited by Fred Oxenby (edited February 01, 2001).]


            ------------------
            Ben Clark
            [email protected]
            If at first you don't succeed, destroy all evidence that you tried.

            Comment


            • #7
              Here is all of the code minus the LibMain.


              '****************** BAS MODULE BEGIN
              Option Explicit

              Public Declare Function WITSSETEVENTHANDLER Lib "eWITS.DLL" (ByVal ConnHandle As Long, ByVal CallBackAddress As Long) As Long

              Public Function WITSCallBack(EventId As Long, msg As String) As Long

              MsgBox "Message received"
              MsgBox "EventID = " + Str$(EventId)
              MsgBox Msg, , Str$(EventId)
              WITSCallBack = 0

              End Function

              '***************** BAS MODULE END


              '***************** BUTTON CLICKED EVENT
              Private Sub Command1_Click()

              Answer = WITSSETEVENTHANDLER(1, AddressOf WITSCallBack)

              End Sub

              '***************** BUTTON CLICKED EVENT END

              '***************** PBDLL CODE
              DECLARE FUNCTION AppCallBack(EventID AS LONG, TheData AS LONG) AS LONG

              DECLARE FUNCTION WITSSetEventHandler(BYVAL ConnHandle AS LONG, BYVAL CallBackAddress AS DWORD) AS LONG

              NORMAL LibMain() goes here

              FUNCTION WITSSetEventHandler(BYVAL ConnHandle AS LONG, BYVAL CallBackAddress AS DWORD) EXPORT AS LONG
              LOCAL Answer AS LONG
              LOCAL EventId AS LONG
              LOCAL Msg AS STRING

              Msg = "This is a test"
              EventId = 2

              CALL DWORD CallBackAddress USING AppCallBack(EventId, STRPTR(Msg)) TO Answer

              FUNCTION = %TRUE

              END FUNCTION

              '***************** PBDLL CODE END

              Originally posted by Don Dickinson:
              could you show your VB declaration for WITSSETEVENTHANDLER

              Thanks,
              Don



              ------------------
              Ben Clark
              [email protected]
              If at first you don't succeed, destroy all evidence that you tried.

              Comment


              • #8
                I'd start (sorry I don't have time to do it right now) by creating a very small PBDLL program that calls the DLL instead of using the VB one. This will tell you if you have some problem specific to VB. Post the results here.
                --Don

                ------------------
                www.basicguru.com/dickinson
                Don Dickinson
                www.greatwebdivide.com

                Comment


                • #9
                  Here might be something.
                  When I call the callback function with the string set
                  to "T", I do get the "T" in the VB callback.
                  If I set it to 2 or more characters I only get ? marks.
                  Could this be a unicode thing??

                  Originally posted by Don Dickinson:
                  could you show your VB declaration for WITSSETEVENTHANDLER

                  Thanks,
                  Don



                  ------------------
                  Ben Clark
                  [email protected]
                  If at first you don't succeed, destroy all evidence that you tried.

                  Comment


                  • #10
                    It looks like I found the answer.
                    The VB callback function is looking for the string to
                    be unicode.
                    If I add this line prior to calling the VB callback
                    it works just fine.

                    MultiByteToWideChar(%CP_ACP, %MB_PRECOMPOSED, Msg, -1, UMsg, 1000)

                    Thanks for everyones help

                    ------------------
                    Ben Clark
                    [email protected]
                    If at first you don't succeed, destroy all evidence that you tried.

                    Comment


                    • #11
                      Ben, This works in my PBDLL and VB6
                      Code:
                      POWERBASIC DLL
                      --------------
                      Declare Function AppCallBack(ByVal EventID As Long, TheData As Long) As Long
                        
                      Function WITSSetEventHandler(ByVal ConnHandle As Long, ByVal CallBackAddress As Dword) Export As Long
                      Local Answer            As Long
                      Local EventId           As Long
                      Local Msg               As String
                         
                      Msg = "This is a test"
                      EventId = 2
                        
                      Call Dword CallBackAddress Using AppCallBack(EventId, StrPtr(Msg)) To Answer
                        
                      End Function
                      ---------------------
                        
                      VISUAL BASIC MODULE
                      
                      Declare Function WITSSETEVENTHANDLER Lib "C:\DISKPB\PBDLL60\AAA.DLL" (ByVal ConnHandle As Long, ByVal CallBackAddress As Long) As Long
                      [b]Declare Function lstrcpyA Lib "Kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long[/b]
                       
                      Sub main()
                       Call WITSSETEVENTHANDLER(3, AddressOf WITSCallBack)
                      End Sub
                        
                      Public Function WITSCallBack(ByVal EventId As Long, ptrMsg As Long) As Long
                      Dim PBMsg$, rc&, pEnd&
                           
                          PBMsg$ = Space(2049)
                          rc& = lstrcpyA(PBMsg$, ptrMsg)
                          pEnd& = InStr(PBMsg$, Chr$(0))
                          If (pEnd& > 0) Then PBMsg$ = Left$(PBMsg$, pEnd& - 1)
                          
                          MsgBox "Message received"
                          MsgBox "EventID = " + Str$(EventId)
                          MsgBox PBMsg$, , Str$(EventId)
                           
                          WITSCallBack = 0
                      End Function

                      ------------------
                      Fred
                      mailto:[email protected][email protected]</A>
                      http://www.oxenby.se

                      Fred
                      mailto:[email protected][email protected]</A>
                      http://www.oxenby.se

                      Comment

                      Working...
                      X