Passing array of DLL Pure to VB [Resolved]

Just starting out? Need help? Post your questions and find answers here.
thearr
User
User
Posts: 21
Joined: Sun Apr 26, 2009 3:18 am
Location: RU

Post by thearr »

Hi, KCC.

I think that there is no way to know the array size except to pass it from DLL.

For example, like you did, as the firs element of the array:

Code: Select all

ProcedureDLL TabloDansLaDll()
 Static Dim Tablo.s(10)
 Tablo(0) = Str(ArraySize(Tablo()))
 Tablo(1) = "String 1"
 ;...
 Tablo(9) = "String 9"
 ProcedureReturn @Tablo()
EndProcedure
Or, maybe a less safe way, to chek for the special end element of the array, e.g.:

Code: Select all

;***DLL***
ProcedureDLL TabloDansLaDll()
 Static Dim Tablo.s(10)
 Tablo(0) = "String 0"
 Tablo(1) = "String 1"
 ;...
 Tablo(9) = "End of Array"
 ProcedureReturn @Tablo()
EndProcedure

'***VB***
Dim Tablo() as Long, TabloPtr as Long, i as Integer

TabloPtr = TabloDansLaDll()
i = -1
Do
 i = i + 1
 ReDim Tablo(0 to i)
 CopyMemory Tablo(i), ByVal TabloPtr + 4*i, 4
Loop Until StringDLL(Tablo(i)) = "End of Array"

ADDED 20.05.09

But actually it's possible to get Purebasic array size:

Code: Select all

ArraySize as Long
CopyMemory ArraySize, ByVal TabloPtr - 8, 4
Debug.Print ArraySize 'Output: Array Size + 1
But this is not documented feature and can be changed unexpectedly.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Excuse me for the late answer :oops:

Thank you for your explanation.
Like this, i'm sure that, they are no more solution, for know the size of array 8)

Again thanks for your precious help.
Thanks to you, i can take again the long road of the programming :D

I wish you a very good day
ImageThe happiness is a road...
Not a destination
Post Reply