Results 1 to 5 of 5

Thread: Passing Array handel in UDT to DLL

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 1999
    Location
    Israel
    Posts
    16

    Post

    I have a function in a c++ dll that gets a pointer to double array. inside a struct.
    I defined a UDT in VB5 and passed all the rest of the UDT fields fine, the problem is with this array.
    type Type1
    par1 as Integer
    myArr as double
    end type
    dim myType as Type1 , arr() as double
    ReDim arr(1000)

    I don't know how to set myType.myArr to point to arr


    if I pass the array seperetly it's easy and it works but I need it in the UDT.
    CALL dllfunction(myType,arr(0))

    Is this posible???
    HELP
    Shai


  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Why don't you Dim the UDT variable directly?, eg.
    Code:
    Type Type1
        Par1 As Integer
        myArr() As Double
    End Type
    
    Dim myType As Type1
    ReDim myType.myArr(1000)

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 1999
    Location
    Israel
    Posts
    16

    Post

    I have tried this with no success.
    I don't know if this is my fault or it's not the right way.

    I will make myself clear.
    the dll is waiting for a UDT with a pointer to a double array.

    ???????????????????????

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    I see, you want to pass a pointer, not the actual array..

    In that case your only option would be to use one of the Undocumented and Unsupported Pointer Functions in VB, like VarPtr() to give you the Pointer to a Local Array which you can store as a part of a User Defined Type.

    Something like:
    Code:
    Type Type1
        par1 As Integer
        myArr As Long
    End Type
    
    Dim myType As Type1
    Dim Arr(1000) As Double
    
    myType.myArr = VarPtr(Arr(0))
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Oct 1999
    Location
    Israel
    Posts
    16

    Post

    10x for the help VarPtr() is working fine!

    Shai

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width