CallDLL, with parameters!

Blitz3D Forums/Blitz3D Programming/CallDLL, with parameters!

Btw, static means nonchaning, but how would a variable that can't change be used to return a result of a function?
Supposing this is really what causes your problem, what you have to do is have a global string variable that stores the return value. So, instead of directly returning the string, store the (string) result in this global variable, and then return this global variable. This is needed because if you directly return the string (supposing this is a simple pointer to the array of characters), then you must understand that being a local variable, the memory (containing the characters) this pointer points to doesn't exist anymore once the funciton as exited, so basically the one who called the DLL function (your blitz application) will try to access an unallocated memory block -> crash. On the contrary if your string is global, it will stay alive after the DLL function exits (the time needed for blitz to copy and convert it into its own internal string format).


Also I don't really know Delphi, but aren't strings handled differently thatn in C? I believe they are encoded with the length first, and then the characters. The string format needed to pass from/to uselib DLLs is the ASCIIZ format (or the "C string" format if you prefer): a string is in this case a simple pointer to the first character of an array of characters that is terminated by 0. Isn't that what is called PChar in Delphi (I think ther are also lib functions to convert back and forth, handling the terminal 0)? Sorry if I'm all wrong, I'm not a specialist at Delphi, not found of it.