Posted: Mon May 18, 2009 9:17 am
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:
Or, maybe a less safe way, to chek for the special end element of the array, e.g.:
ADDED 20.05.09
But actually it's possible to get Purebasic array size:
But this is not documented feature and can be changed unexpectedly.
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
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