Ok, I'm pretty new to the C++ area but not to programming. I program in various other languages and some of the basics are the same but a lot of it is not. for example in my world strings are variables that hold text and with C++ it appears strings are Objects pointing to a memory location that hold the text. what I need is to take a function that takes std::string and returns a char * for example.
1 2 3 4 5
char * myFunction(std::string INMSG)
{
// add text message "some text here" and join with INMSG
// and then return the combined text in char *
}
Well i've tried to return the std::string and it causes the external application to crash. i've tried returning char * and it didn't crash at all but I couldn't build the string in the function. i've been able to return an int and a double but not a string. Oh i'm loading the DLL with a program called MetaTrader 4. am I doing this the wrong way?
When you return the char*, are you taking steps to ensure that the memory it points to is not being released for other use (i.e. written over by something else)?
char* XPortMsg(string inmsg)
{
// // take the string and perform operations
// assemble a string for example
char* retVal = "USER: ";
// then I want to take the string and
// assemble it like
char* retVal2 = retVal + inmsg.c_str();
return retVal2;
}