Hello, I have the following code snippet, when the function "GetHOSTSFilePath" is called it should return the the location of the HOSTS file. However, in my case the string is truncated (no idea why).
char *GetWindowsPath() {
char szWindowsPath[MAX_PATH];
GetWindowsDirectory(szWindowsPath, sizeof(szWindowsPath));
return szWindowsPath;
}
char *GetHOSTSFilePath() {
char szBuffer[MAX_PATH];
wsprintf(szBuffer, "%s\\system32\\drivers\\etc\\hosts", GetWindowsPath());
return szBuffer;
}
Any ideas could be helpful. Thanks in advance.
Regards,
halsten
Your char buffers will be destroyed when the app leaves the functions, try static.
static char szWindowsPath[MAX_PATH];
and
static char szBuffer[MAX_PATH];
John
Thanks a lot, that worked like a charm.