using GetPrivateProfileSectionNames for UNICODE

Posted on 2011-10-25
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

Question by:BrianDumas

    Author Comment

    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
    LVL 6

    Expert Comment

    What does GetLastError function returns? call this function just after GetPrivateProfileSectionNames call and let us know the error code

    Author Comment

    GetLastError returns "The operation completed successfully."
    LVL 86

    Accepted Solution

    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

    LVL 6

    Expert Comment

    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.

    Author Closing Comment

    Thanks for the quick and accurate help

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Are you unable to synchronize your OST (Offline Storage Table) file with Microsoft Exchange Server? Is your OST file exceeding 2 GB size limit? In Microsoft Outlook 2002 and earlier versions, there is a 2 GB size limit for the OST file. If the file …
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now