it won't work because the array of char that the returned pointer is pointing to will cease to exist (the array of char inside the string object), leaving you with a pointer to memory that could be anything.
Ideally, change exPath() to return a string. Can you change what exPath() returns?
Also, this function exPath(). Is this going to be called from other libraries or executable? That also adds complication.
> I already tried to use c_str() function but it didn't work well.
c_str() will give you a const pointer to the buffer used by the string, the problem is that the string dies at the end of the function, so you are pointing to garbage.
as an alternative
1 2 3
cdll char* exPath() { //your client should `free()' the returned c-string
return strdup(ExePath().c_str());
};