I need to return an array of int(s) from a function in my c code.
I suspect I have to either
soft declare function ABC lib SomeLib () as ptr
the C code I’m working with has the array constructed. Not sure how to pass it back a) because I won’t know the size of the array when calling from xojo and b) I’m not sure how I’d free the memory after.
ptr as return is good, so make a memory block, keep a reference somewhere and return it.
Pretty sure you want as Ptr
index from that more or less like you would with C
const sizeofInt = 4
const sizeOfInt = 8
myVariable = Ptr( offset * sizeOfInt ).Integer
// or you can use the specific size - either Int32 or int64
a declare into free would be in order for Xojo to release the memory allocated
Sorry, I had the other way.
So in C you keep the array and return to Xojo, where you get it as ptr.
Then use p.Int32() or p.Int64 to access it.
I think I get this… I am not accustomed to C programming though.
In the C function, if I return a pointer to the array, it will just be to local values won’t it?
I have tried this, and it blew up… however I can’t be sure it wasn’t just bad programming on my part.