I am writing a wrapper for the Leadwerks Engine DLL and I've came across a snag. Well, not so much of a snag as an ugly mess. I'm trying to determine the best way to pass struct data back and forth from DBP to my wrapper.
The struct in question is a LE struct called TVec3(and other derivations). This struct is used in some LE commands in order to specify a 3 point float with the command Vec3(x#,y#,z#), which returns said struct. My messy solution to this was to predefine an array and use integer indexes to that array instead of the actual pointer. Every time my wrapper's version of Vec3 is called, the pointer is stored at the index and that index is returned as an integer. When the array is full, it starts at the beginning and overwrites previous values in the array.
I would like to do away with the array(if possible), and make my Vec3 command function as closely as possible to the original LE command. So, my question is, what is the best way to handle structs in and out of a dll? I'm sure it could be done more elegantly with pointers, but when it comes to C/C++, pointers are my mortal enemy. I blame years of procedural programming
Thank for any help!
Randy
EDIT:
I think I may have figured it out. Think being the keyword.
EXPORTC void dbAddBodyForce(DWORD body, DWORD force, int global) { AddBodyForce((TBody)body,*(TVec3*)&force, global); }
EXPORTC DWORD dbVec3(float x, float y, float z) {
TVec3 vec3 = Vec3(x,y,z);
return *(DWORD*)&vec3;
}
If I'm not mistaken, that should work. If anyone sees a problem with this, lemme know. Like I said, I am TERRIBLE at pointers, lol.