Raymond Fanning
Member
Hi all. I'm having some trouble with a pathfinding extension I'm trying to write. The first real function of the extension that I'm trying to test out is the function to make the grid object for pathfinding, and I figured that I could cast a pointer to the object into a string and pass that back to GameMaker in the function. The I wrote is as follows:
(note: fn_export is a macro for __declspec(dllexport))
So the weird part is that as far as I can tell there's no reason it shouldn't work. However, any attempt to get data out of the function results in GameMaker storing an empty string (""). The return type is fine, as returning a string literal such as "Test" is passed successfully into GMS. Likewise, if I plug the code I have into an actual console application instead of a .dll and print the return value I'll get a string holding the memory address of the grid object as expected (so, something like "0x0C240e08"). It just seems like something gets lost in translation between actually creating the c_str object and passing back into GMS. Does anyone have any insight into why this might be happening or what I'm doing wrong? Thanks!
Code:
fn_export const char* make_grid(double w, double h) {
//create the grid
Grid* new_grid = new Grid(int(w), int(h));
//cast the address of the grid to a string to return to gamemaker
const void* address = static_cast<const void*>(new_grid);
stringstream ss;
ss << address;
const string s = ss.str();
return s.c_str();
}
So the weird part is that as far as I can tell there's no reason it shouldn't work. However, any attempt to get data out of the function results in GameMaker storing an empty string (""). The return type is fine, as returning a string literal such as "Test" is passed successfully into GMS. Likewise, if I plug the code I have into an actual console application instead of a .dll and print the return value I'll get a string holding the memory address of the grid object as expected (so, something like "0x0C240e08"). It just seems like something gets lost in translation between actually creating the c_str object and passing back into GMS. Does anyone have any insight into why this might be happening or what I'm doing wrong? Thanks!
Last edited: