Announcement

Collapse
No announcement yet.

pointers

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

  • Doug McDonald
    replied
    Semen, thank you it was just what i needed. Don't know how i overlooked that. I know about the UDT alignment issues and that In /Out won't work under NT / 2000.

    Thanks
    Doug

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

    Leave a comment:


  • Semen Matusovski
    replied
    Doug --
    You can simply declare Sub PBOUT(ByVal PT As Integer, ByVal t2 As Byte Ptr) Export and do not use StAddress at all, but:
    1) You forgot, that alignment in VB UDT and PB UDT are different.
    The easyiest way in your case to declare all parameters in UDT as Long or to pass string from VB (MKI$ ... + MKL$ + ...).
    2) Don't forget that under NT/2000 you can't use IN/OUT.

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

    Leave a comment:


  • Doug McDonald
    replied
    Tom, Thanks for replying. I had the arguements passed byval at one time. The code above was just the last state it was in and I should have corrected that before posting it. The problem is that the PB6 code won't compile. I get an error at value = @t2

    Tanks

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

    Leave a comment:


  • Tom Hanlin
    replied
    Originally posted by Doug McDonald:
    SUB PBOUT(BYVAL PT AS INTEGER, StAddress AS DWORD) EXPORT
    Since you're passing the UDT from Visual Basic BYREF, and you want to see it as a pointer on the PowerBASIC side, you need to receive the value BYVAL on the PowerBASIC side.
    Code:
    SUB PBOUT(BYVAL PT AS INTEGER, BYVAL StAddress AS DWORD) EXPORT
    Also, in your VB code you've declared PT as being passed BYREF, whereas you've told PowerBASIC that it's passed BYVAL. Since we're not expecting to convert the value to a pointer, here, you want the two to match up. In this case, the best place to change it is probably on the VB side:
    Code:
    Declare Sub PBOUT Lib "port32.dll" (ByVal pt As Integer, mtype As myType2)
    Finally, it's very important to realize that Visual Basic uses a unique alignment method for UDT members, so a UDT in VB may not match the same UDT in PowerBASIC! See the FAQ for more information on this.

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

    Leave a comment:


  • Doug McDonald
    started a topic pointers

    pointers

    Ok I'm lost, I'm tring to pass a pointer for a UDT from VB to pb6
    then send it to an I/O port a byte at a time. This code will not
    compile but it will if i pass a VARPRT of a string from VB (changing
    some of the code of course). The problem is value = @t2. I thought, and
    I'm wrong, that @t2 would be a pointer the the first byte of the
    structure.

    'pb code:

    #COMPILE DLL "c:\windows\system\port32.dll"
    '#INCLUDE "win32api.inc"

    TYPE myType1
    t1mytype2 AS LONG
    END TYPE

    TYPE myType2
    testInt AS INTEGER
    testUDT AS myType1
    testLong AS LONG

    END TYPE

    SUB PBOUT(BYVAL PT AS INTEGER, StAddress AS DWORD) EXPORT
    DIM t2 AS myType2 PTR
    t2 = StAddress



    DIM i AS LONG
    DIM value AS BYTE
    FOR i = 0 TO LEN(myType2)
    value = @t2
    ! mov AL, value
    ! mov DX, PT
    ! out DX, AL
    INCR t2
    MSGBOX HEX$(value)
    NEXT i

    END SUB

    FUNCTION PBINP(BYVAL PT AS INTEGER) EXPORT AS LONG
    ! mov DX, PT
    ! in AL, DX
    ! mov FUNCTION[0], AL
    END FUNCTION


    'VB Code:

    Type myType1
    t1mytype2 As Long
    End Type

    Type myType2

    testInt As Integer
    testUDT As myType1
    testLong As Long

    End Type


    Declare Sub PBOUT Lib "port32.dll" (pt As Integer, mtype As myType2)


    Dim t1 As myType1
    Dim t2 As myType2

    Private Sub Command1_Click()
    t1.t1mytype2 = &HFFFFFFFF
    t2.testInt = &HFFFF
    t2.testLong = &HFFFFFFFF

    PBOUT 300, t2

    End Sub

    Private Sub Command2_Click()
    End
    End Sub
Working...
X