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

BrianDumasAsked:
Who is Participating?
 
jkrCommented:
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)) {

  vResult.push_back(p);

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

Open in new window

0
 
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
0
 
rushtoshankarSr Manager Software DevelopmentCommented:
What does GetLastError function returns? call this function just after GetPrivateProfileSectionNames call and let us know the error code
0
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."
0
 
rushtoshankarSr Manager Software DevelopmentCommented:
http://www.codeproject.com/KB/cpp/UNICOD_inifile.aspx
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.
0
 
BrianDumasAuthor Commented:
Thanks for the quick and accurate help
0
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.