Announcement

Collapse
No announcement yet.

Trouble with Double

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

    Trouble with Double

    I allways get an error using a VB6 callback;

    Code:
    PB6;
    DECLARE Sub VBDEBUG ( ByVal ID As Long, Param1 As Double, Param2 As Double, Param3 As Double, Param4 As Double, Param5 As Double )
    
    Global VBCallBack As DWORD
    
    Sub DOVBCALL CDECL ( [ID As Long _
        , Param1 As Double _
        , Param2 As Double _
        , Param3 As Double _
        , Param4 As Double _
        , Param5 As Double _
        ] )
    
        If Clng( VBCallBack ) = 0 Then Exit Sub
    
        Call DWORD VBCallBack USING VBDEBUG( ID, PARAM1, PARAM2, PARAM3, PARAM4, PARAM5 )
    
    End Sub
    
    VB6;
    Sub MyVBDebug ID As Long _
        , Param1 As Double _
        , Param2 As Double _
        , Param3 As Double _
        , Param4 As Double _
        , Param5 As Double _
        )
    
    'Overflow error (6)
    
    End Sub
    If i change the parameters to long, it works fine.
    I need doubles.

    VB's addressof is used to set the PB's value 'VBCallBack'.
    ???


    #2
    The PB code shows that you want the compiler to pass the "ID" variable BYVAL and the rest of the parameters BYREF - but the VB code shows all parameters are expected to be passed BYREF.

    Did you actually paste this code directly into this message, or did you retype it? I ask simply because the VB code is missing an opening-parenthesis, which could explain the missing BYVAL.

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


      #3
      Sorry, i retyped it.
      I tried several methods, all byval , all byref etc..

      The error occures only once(!)
      When i click a VB button wich activates the callback in PB, VB stops with the error (6).
      When i continue i get the msgbox placed in this VBcallback procedure. (test)
      When i click this button again, the procedure does not produce an error.
      Only when i restart the app (F5).

      The weird part is, when i remove the Double parts, it's all ok.
      I even tried a type instead of the parameters.

      I don't know what's happening, it seems that exchanging the doubles is a problem..

      Hope to here an answer on this subject.

      My colleague needs a VB debug where he can set variables from within VB in PB.
      The calculations are that big that he can't use simple methods like msgbox's etc..

      Thanks,



      ------------------

      Comment


        #4
        VB error 6 is an overflow error, right?

        The PB sub uses CDECL but VB does not call with CDECL, it uses BDECL instead, so your parameter order is effectively reversed when VB passes the parameters to the PB code.

        It certainly looks like the problem relates to how you are passing parameters to the PB SUB initially.

        Cut & paste all of the relevent code (both VB and PB declares and the SUB prototypes) so we can see *exactly* what you are using, instead of a retyped "summary". Thanks!

        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


          #5
          This does work however, in our large app ~370k DLL, an error still occures.(???)
          I don't know where to look, i guess i need to strip the app.
          We use a lot of string literals.


          Code:
          $IF 0
          
          VB callback example;
          
          Option Explicit
          
          '// c:\pbwork\vbdebug\vbdebug.dll
          'ProjectID   : 108
          'Project     : VBDebug
          'Module      :
          'Date pasted : 2000-2-16 / 16-02-2000 14:01:22
          Declare Sub SetVBCVALLBACK Lib "C:\PBWORK\VBDEBUG\VBDEBUG.DLL" Alias "SETVBCVALLBACK" (ByVal AddressOfVB As Long)
          Declare Sub RunVBCall Lib "C:\PBWORK\VBDEBUG\VBDEBUG.DLL" Alias "RUNVBCALL" ()
          
          Sub VBDEBUG(ByVal ID As Long, Param1 As Double, Param2 As Double, Param3 As Double, Param4 As Double, Param5 As Double)
          
          '    Stop
              MsgBox ID & ", " & Param1 & ", " & Param2 & ", " & Param3 & ", " & Param4 & ", " & Param5
          
          End Sub
          
          Option Explicit
          
          Private Sub Command1_Click()
          
              SetVBCVALLBACK Val(AddressOf VBDEBUG)
              RunVBCall
          
          End Sub
          
          
          $ENDIF
          
          DECLARE Sub VBDEBUG ( ByVal ID As Long, Param1 As Double, Param2 As Double, Param3 As Double, Param4 As Double, Param5 As Double )
          
          Global VBCallBack As DWORD
          
          Sub DOVBCALL CDECL ( ParamCount As Long _
             [,ID         As Long _
              , Param1    As Double _
              , Param2    As Double _
              , Param3    As Double _
              , Param4    As Double _
              , Param5    As Double _
              ] )
          
              Dim pID As Long
              Dim p1 As Double
              Dim p2 As Double
              Dim p3 As Double
              Dim p4 As Double
              Dim p5 As Double
          
              If Clng( VBCallBack ) = 0 Then Exit Sub
          
              If ParamCount > 0 Then pID = ID
              If ParamCount > 1 Then P1 = Param1
              If ParamCount > 2 Then P2 = Param2
              If ParamCount > 3 Then P3 = Param3
              If ParamCount > 4 Then P4 = Param4
              If ParamCount > 5 Then P5 = Param5
          
              Call DWORD VBCallBack USING VBDEBUG( pID, P1, P2, P3, P4, P5 )
          
              If ParamCount > 0 Then ID     = pID
              If ParamCount > 1 Then Param1 = P1
              If ParamCount > 2 Then Param2 = P2
              If ParamCount > 3 Then Param3 = P3
              If ParamCount > 4 Then Param4 = P4
              If ParamCount > 5 Then Param5 = P5
          
          End Sub
          
          Sub SetVBCVALLBACK( ByVal AddressOfVB As Long ) EXPORT
          
              VBCallBack = CDWD( AddressOfVB )
          
          End Sub
          
          Sub RunVBCall() EXPORT
          
              DOVBCALL 0
              DOVBCALL 6, 100, 1, 2, 3, 4, 5
          
          End Sub
          ------------------

          Comment

          Working...
          X
          😀
          🥰
          🤢
          😎
          😡
          👍
          👎