Page 2 of 2

Posted: Mon May 18, 2009 9:17 am
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.

Posted: Mon May 25, 2009 11:59 am
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