GetPrivateProfileString

1
2
3
char buffer[MAX_PATH];
wstring currentFile = s2ws(info->fileName);
GetPrivateProfileString(currentFile.c_str(), TEXT("ENABLED"), TEXT("InvalidFileName"), LPWSTR(buffer), MAX_PATH, fileLocation.c_str());


For some reason buffer is filled with the first letter of the value, anyone know where I'm going wrong?
Last edited on
Bump anyone?
'LPWSTR' says that you get UTF-16 characters. so your buffer is filled with like

buffer[] = { 'A', 0, 'B', 0, 'C', 0 };

what you see is of course just the first char but all other are present. So either you continue using UTF-16 or you convert it to whatever

or

use GetPrivateProfileStringA
LPWSTR(buffer)

Don't cast around compiler errors. If the compiler complains without the cast, it means you're doing something wrong. Casting does not fix the problem, it just shuts the compiler up.

As coder777 suggested, this is a problem with char vs. wchar_t.

See this for details: http://www.cplusplus.com/forum/articles/16820/
GetPrivateProfileStringA was a good one, thanks! Problem solved.
Topic archived. No new replies allowed.