Moving array data with a DLL. [Help]
BlitzMax Forums/BlitzMax Programming/Moving array data with a DLL. [Help]
| ||
I have a DLL written in Bmax (with Sweenie's MakeDLL tool). I want to transfer a pointer to an array from the host to the dll and have the dll populate the array. I've tried this a dozen different ways and each one just crashes Bmax. Here is the Dll function. '// Maparray[,] is declared global in the dll and populated Function GetMapTest:Int(map:Int Ptr) "win32" 'EXPORT GCEnter() Local p:Int Ptr p = map Local X:Int, Y:Int, I:Int For X = 0 To MAPW - 1 For Y = 0 To MAPH - 1 p[(X * MAPW) + Y] = MapArray[x, y] Next Next Return True End Function Here is how the host in bmax is calling the function. Global Maparray:Int[(MAPH * MAPW)] Local tmp:=Int Ptr tmp = Varptr Maparray[0] GetMapTest(tmp) <-- CRASH!! I know that I could just pass Bmax arrays around directly, but i want this dll usable by other languages. How is it possible to get array data from a dll. Can anyone clue me in? Thanks |
| ||
Why are you only passing the first index?tmp = Varptr Maparray[0] You are going beyond map's limits in: For X = 0 To MAPW - 1 For Y = 0 To MAPH - 1 p[(X * MAPW) + Y] = MapArray[x, y] Next Next |
| ||
Its not the first index, its a pointer to the beginning of the array. |
| ||
Its not the first index, its a pointer to the beginning of the array. You dont need to specifically do that anymore, a straight Local p:Int Ptr = arrayshould suffice ;) It could be (X*MAPW)+Y is not correct, if the width is not same as height you wont get the result you expect. im guessing what you want is X+(Y*MAPW)? |
| ||
You dont need to specifically do that anymore, a straight Local p:Int Ptr = array should suffice ;) hmm.. When did that change? that does work. Thanks Your right about the map dimensions too that are being calculated. that was causing some additional explosions. Thanks! |