Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

using GetPrivateProfileSectionNames for UNICODE

Posted on 2011-10-25
6
Medium Priority
?
656 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:BrianDumas
  • 3
  • 2
6 Comments
 

Author Comment

by:BrianDumas
ID: 37026173
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
 
LVL 6

Expert Comment

by:rushtoshankar
ID: 37026244
What does GetLastError function returns? call this function just after GetPrivateProfileSectionNames call and let us know the error code
0
 

Author Comment

by:BrianDumas
ID: 37026296
GetLastError returns "The operation completed successfully."
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 37026307
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
 
LVL 6

Expert Comment

by:rushtoshankar
ID: 37026333
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
 

Author Closing Comment

by:BrianDumas
ID: 37026491
Thanks for the quick and accurate help
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is only natural that we all want our PCs to be in good working order, improved system performance, so that is exactly how programs are advertised to entice. They say things like:            •      PC crashes? Get registry cleaner to repair it!    …
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question