Strings in C++ are simply pointers to an array of characters, terminated by a null character. Hence why they have the type 'char*' (pointer to char).
Each character in the array is a byte specifying the ASCII code of that character. An ASCII code of 0 is a null character.
A pointer is a memory address, so casting 65 to a (char*) will make a pointer pointing to whatever memory is at address 65. This is certainly outside the memory region of you application, and so will cause a crash.
Dealing with arrays can be time consuming, so luckily C++ provides a number of built in functions for dealing with them.
http://www.cplusplus.com/reference/clibrary/cstring/
The easiest thing to do is use the std::string class, which hides all this detail from you. However, you will still need to delete any strings returned by DarkGDK after using them.
Here is a function which will make your life a lot easier:
inline std::string ToStr(const char* str)
{
std::string result = str;
delete[] str;
return result;
}
To use it, add '#include <string>' to the top of your header file, and then paste that code into the header file. It will automatically free any GDK strings after converting them to a std::string.
Whenever you use a GDK function which returns a string, put ToStr() around it. Use std::string for all string variables, and when you need to pass a string to a GDK command, you will need to call 'myVar.c_str()' to convert it back to the type of string which GDK understands.
Example:
std::string myVar = ToStr(dbStr(5));
dbPrint(myVar.c_str());
Not difficult as long as you remember
[b]