Announcement

Collapse
No announcement yet.

Really confused and needs help

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

  • Really confused and needs help

    I have a VB application that creates a structure.
    I have a PBDLL 6 DLL that I created that uses the same structure.
    When I pass the structure from VB to the DLL, the values
    in the structure are wrong.
    The structure looks like this.
    Type typGeneralTimeBased_Record1
    strWellid As String * 16
    intStknum As Integer
    intRecid As Integer
    lngSeqid As Long
    lngDate As Long
    lngTime As Long
    intActcod As Integer
    sngDeptbitm As Single
    sngDeptbitv As Single
    sngDeptmeas As Single
    sngDeptvert As Single
    End Type
    I copied this into the PBDLL and when run gives the wrong answers.
    I looked through the docs and PBDLL says to use DWORD when
    defining structures. I did that and the answers are still wrong
    but not the same as before.

    If you will email me I will send you both the
    VB app and the PBDLL app to show you.

    Thanks
    Ben Clark
    [email protected]

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

  • #2
    hi ben

    this issue (and many other interoperability issues for pb/vb)
    is covered in the faq section of this forum. here's a direct
    link to the relevant section: http://www.powerbasic.com/support/pb...hread.php?t=28

    cheers

    florent

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

    Comment


    • #3
      More than sure that Ben didn't add in PB declaration
      Reserved As Integer beetween intActcod As Integer and sngDeptbitm As Single.


      ------------------
      E-MAIL: [email protected]

      Comment


      • #4
        Semen pointed out the diffrence VB-UDT and PB-UDT
        This is a working code
        VB-Projekt
        Code:
        Type typGeneralTimeBased_Record1
         strWellid As String * 16
         intStknum As Integer
         intRecid As Integer
         lngSeqid As Long
         lngDate As Long
         lngTime As Long
         intActcod As Integer
         sngDeptbitm As Single
         sngDeptbitv As Single
         sngDeptmeas As Single
         sngDeptvert As Single
        End Type
        Public Declare Function ShowMe Lib "C:\DISKPB\PBDLL60\VBTEST.DLL" Alias "SHOWME" (M As typGeneralTimeBased_Record1) As Long
        ---------
        Sub main()
        Dim M As typGeneralTimeBased_Record1
          With M
           .strWellid = "ABCDEFGHIJKLMNOP"
           .intStknum = 1
           .intRecid = 2
           .lngSeqid = 3
           .lngDate = 4
           .lngTime = 5
           .intActcod = 6
           .sngDeptbitm = 1.111111
           .sngDeptbitv = 2.222222
           .sngDeptmeas = 3.333333
           .sngDeptvert = 4.444444
          End With
          x& = ShowMe(M)
          
        End Sub
        PB-DLL code
        Code:
        Type MyType
         strWellid   As String * 16 
         intStknum   As Integer
         intRecid    As Integer
         lngSeqid    As Long
         lngDate     As Long
         lngTime     As Long
         intActcod   As Integer
         [b]padding     As Integer[/b]
         sngDeptbitm As Single
         sngDeptbitv As Single
         sngDeptmeas As Single
         sngDeptvert As Single
        End Type
          
        Function ShowMe(M As MyType)Export As Long
        Local Text$
           
          Text$ = "strWellid   = " & Rtrim$(M.strWellid,Any Chr$(0,32)) & $CRLF & _
          "intStknum   = " & Format$(M.intStknum) & $CRLF & _
          "intRecid    = " & Format$(M.intRecid)  & $CRLF & _
          "lngSeqid    = " & Format$(M.lngSeqid)  & $CRLF & _
          "lngDate     = " & Format$(M.lngDate)   & $CRLF & _
          "lngTime     = " & Format$(M.lngTime)   & $CRLF & _
          "intActcod   = " & Format$(M.intActcod) & $CRLF & _
          "sngDeptbitm = " & Format$(M.sngDeptbitm) & $CRLF & _
          "sngDeptbitv = " & Format$(M.sngDeptbitv) & $CRLF & _
          "sngDeptmeas = " & Format$(M.sngDeptmeas) & $CRLF & _
          "sngDeptvert = " & Format$(M.sngDeptvert)
          MsgBox Text$
          Function = 1
        End Function
        ------------------
        Fred
        mailto:[email protected][email protected]</A>
        http://www.oxenby.se



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

        Comment


        • #5
          OK, just when I think I got it all figured out I run into
          another wall.
          I follow the byte packing and all that stuff that VB does
          but here is the rub.
          I have another structure that looks like the following:

          TYPE typWellIdentification_Record23
          strWellid AS STRING * 16
          intStknum AS INTEGER
          intRecid AS INTEGER
          lngSeqid AS LONG
          lngDate AS LONG
          lngTime AS LONG
          intActcod AS INTEGER
          padHERE AS INTEGER <<<<<<
          strWellname AS STRING * 32
          strWellnum AS STRING * 16
          strOperator AS STRING * 32
          strWellclas AS STRING * 16
          strLocation AS STRING * 32
          strWellutm AS STRING * 16
          strWelllat AS STRING * 16
          strWelllon AS STRING * 16
          strField AS STRING * 32
          padORPADHERE AS INTEGER <<<<<<
          sngElevdp AS SINGLE

          There is 2 places marked above. According to everything
          that I have read, the padding should be after the
          INTEGER intActcod. However, this does not work.
          I have to put the padding after all of the string variables.
          So, does anyone know of any other exceptions to the padding
          rule so that I won't have to keep going though trial
          and error to track these down?

          Thanks again for everyone help and responses.




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

          Comment


          • #6
            Well, you have to consider strings......
            Strings are aligned at byte-boundaries so
            the first padding is not necessary
            Code:
            Type typWellIdentification_Record23
                strWellid   As String * 16
                intStknum   As Integer
                intRecid    As Integer
                lngSeqid    As Long
                lngDate     As Long
                lngTime     As Long
                intActcod   As Integer
                [b]'padHERE     As Integer               'No padding<<<<<<[/b]
                strWellname As String * 32
                strWellnum  As String * 16
                strOperator As String * 32
                strWellclas As String * 16
                strLocation As String * 32
                strWellutm  As String * 16
                strWelllat  As String * 16
                strWelllon  As String * 16
                strField    As String * 32
                padHERE     As String * 2               '<<<<<<
                sngElevdp   As Single
            End Type

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



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

            Comment

            Working...
            X