I have been working on a DLL to be used by an external EXE file. One of my exposed functions is: … char current_version = "“1.1"”; … extern ““C”” _declspec(dllexport) char version(){ return current_version; } Since this is used in many places I made the current_version variable. If I change the code as below, can the caller of the version function change the content of current_version variable? … const char current_version = "“1.1"”; //this is preferable … extern ““C”” _declspec(dllexport) char version(){ char local_copy[100] = make_local_copy(current_version); return local_copy; } Would the local_copy variable be deleted after execution? If yes, how can I return a pointer to const char?

Hi,

What you need to do is:

void version(char **pVersion, int length)
{
strncpy(*pVersion, EYECATCHER_Version, length);
}

Where EYECATCHER_Version is defined as a global constant somewhere in your code

i.e.
static const char * EYECATCHER_Version = “1.0.0” ;

Regards,
Roger Lacroix

Why do you want to make a local copy?

Once all the DLLs are loaded, you are working in the same process. There is no reason I can see not to just use the one copy.