passing to a dll
BlitzMax Forums/BlitzMax Programming/passing to a dll
| ||
how do I fill and pass a c struct to a dll from max in c: typedef struct dsFunctions { Int version; /* put DS_VERSION here */ /* version 1 data */ void (*start)(); /* called before sim loop starts */ void (*doStep) (Int pause); /* called before every frame */ void (*command) (Int cmd); /* called If a command key is pressed */ void (*stop)(); /* called after sim loop exits */ /* version 2 data */ char *path_to_textures; /* If nonzero, path To texture files */ max: extern Function dsSimulationLoop(argc:Int,argv:BytePtr,window_width:Int,window_height:Int,dsFunctions:Byte Ptr) end extern filling up a type and sending a pointer to it doesnt seem to work, the dll function runs but doesnt get the right version number typedef dsFunct field ver:int field start_p:var ptr .. .. enddef dsf:dsFunctions=New dsFunctions dsf.ver=2 .. .. dsSimulationLoop (0,Null,352,288,Varptr dsf) |
| ||
I believe that BlitzMAX types have several other 'internal' fields in addition to those you specify in the code. The easiest option would probably to create a block of memory using MemAlloc and then insert the data there. It would be nice to have a function which converts BlitzMAX types to C Structs though. |
| ||
notice the first byte(2) this is the first int in the structure and the dll does get the value of 2 how would i get a function pointer into dsf[4..7] Global dsf:Byte[]=[Byte(2),Byte(0),Byte(0),Byte(0).. ,Byte(0),Byte(0),Byte(0),Byte(0).. ,Byte(0),Byte(0),Byte(0),Byte(0).. ,Byte(0),Byte(0),Byte(0),Byte(0).. ,Byte(0),Byte(0),Byte(0),Byte(0).. ,Byte(0),Byte(0),Byte(0),Byte(0)] st=Int(Byte Ptr start) Local pnt:byte pnt=var(dsf+5) pnt=st Print "st="+Hex(st) Print "d4="+dsf[4] Print "d5="+dsf[5] Print "d6="+dsf[6] Print "d7="+dsf[7] |
| ||
I believe that BlitzMAX types have several other 'internal' fields in addition to those you specify in the code. I think they changed it. You can see several cases in their modules where they define a C++ struct direclty within bmax. (I.e to recieve c++ made structures.) |
| ||
It seems it's ok to use a type as a C struct substitute: http://www.blitzbasic.com/Community/posts.php?topic=41809 |