using GetPrivateProfileSectionNames for UNICODE

Using VS2008.
My code is attached. It always returns slength==0. And no strings in the szResult. Can anyone show me how to get this working ina UNICODE environment?

char* szResult = new char[2000];
memset(szResult, 0x00, 2000);
int slength=GetPrivateProfileSectionNames((LPWSTR)szResult, 2000, (LPWSTR)m_szFileName);

Open in new window

Who is Participating?
For UNICODE, you'd just use
wchar_t* m_szFileName = L"c:\\windows\\myfile.ini";
wchar_t* szResult = new wchar_t[2000];
memset(szResult, 0x00, 2000 * sizeof(wchar_t));
int slength=GetPrivateProfileSectionNamesW(szResult, 2000, m_szFileName);

Open in new window

Parsing that is pretty much the same as doing that with ANSI value, just that's UNICODE instead:
std::vector<std::wstring> vResult;

wchar_t* p = szResult;

while (*(p + 1)) {


  p += (wcslen(p) + 1);

Open in new window

BrianDumasAuthor Commented:
Also, please show how to parse the szResult to get each section name from it. I am storing the section names in a vector of std::string type.

Thanks, Brian
rushtoshankarSr Manager Software DevelopmentCommented:
What does GetLastError function returns? call this function just after GetPrivateProfileSectionNames call and let us know the error code
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

BrianDumasAuthor Commented:
GetLastError returns "The operation completed successfully."
rushtoshankarSr Manager Software DevelopmentCommented:
Check this. This page has the class with appropriate members to read the data. If it works we can do the parsing in the next step.
BrianDumasAuthor Commented:
Thanks for the quick and accurate help
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.