So now your returning a pointer to the stack that gets invalidated, and will fail if GM users more stack space before it copies that string. To safely return a string it must be located some where that doesnt get invalidated by the return (e.g. a string literal, static var or global).
Oh and dynamically sized stack arrays are not in the C++ standard, thats a C99 feature (another case where "C++ is a superset of C" is wrong). Many compilers wont accept that syntax (you can do it yourself with somthing like alloca but thats fairly advanced stuff, but still wont solve the string invalidation issue).
Heh, I actually originally had it use strcpy() to copy the data over to a C-string and return that, but I didn't think it was necessary. If it is, I can always add it back, but I think we should focus on getting it to compile at all first .
Sorry I took your post as you got it to compile on the compilers you have with some settings, but the DLL was crashing GM, hence the list of things you can do to cause a crash
This I don't understand. If you're talking about the __declspec, I already have that... Sorry if I sound stupid here, but I don't have a ton of experience in C++, just a little bit (2.5 semesters of school for it and a tiny bit of personal use).
It is not a C++ detail as such, but more a fundamental one about how the CPU works. The CPU has a bunch of registers, as well as the computers main memory, a portion of which is used as the stack. Data is added and removed from the top of the stack.
The calling convention defines how a function is called, since it turns out there are many ways to use the stack and available registers to pass parameters and get return values, as well as if the caller or callee should clean up the stack, and which registers to use for various purposes.
GameMaker supports the stdcall and cdecl calling conventions for extension DLL's. Both pass all their parameters on the stack in right to left order (so for the function f(a,b,c) the machine code pushes the values of c, b and a onto the stack in that order), use the EAX register for the return value, and additonally define the ECX and EDX registers for the functions use (the other data registers must be preserved, that is they must hold the same value after the function as they did at the start). The difference between these two is that in stdcall the callee cleans up the stack (POP's the parameters from it) and with cdecl the caller cleans it up. The result is that if the caller and callee use different conventions, you may corrupt the stack by either cleaning it twice, or not at all.
There are also a number of other calling conventions.
Edited by SyncViews, 16 September 2011 - 12:15 AM.