Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DLL Talk / Passing Structs to and from DLLs

Author
Message
Coldfire
10
Years of Service
User Offline
Joined: 22nd Oct 2008
Location: Indiana
Posted: 6th Jan 2011 17:46 Edited at: 6th Jan 2011 18:02
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.



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.
Benjamin
16
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 6th Jan 2011 18:22
You can't return the address of a local variable, since the variable won't exist when the function exits.

Coldfire
10
Years of Service
User Offline
Joined: 22nd Oct 2008
Location: Indiana
Posted: 6th Jan 2011 18:40 Edited at: 6th Jan 2011 18:47
I thought that may be the case, but I was not sure. So, in other words, I'm stuck with using these messy integer indexes? There has to be a more elegant solution. Leadwerks does not use numerical indexes, and as such, I do not want my wrapper to either.

EDIT: I also received a response on the Leadwerks forums concerning this situation. In that response, I was reminded about the list functions and have decided to go that route for management so that I may do away with numerical indexes. Thanks for the help.

Login to post a reply

Server time is: 2019-10-17 04:22:34
Your offset time is: 2019-10-17 04:22:34