GetPrivateProfileString

Hi-

I'm using MS VC++ 6.0. I need to get some information out of an .ini file and someone told me that GetPrivateProfileString no longer works in 6.0. I have looked into it and this seems to be the case. How do I read information from an .ini file using VC++ 6.0?

Thanks
jmnolanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

IexpertCommented:
Of course it works?
It has nothing to do with VC6? It's part of the windows
API.

just #include <windows.h>

and use GetPrivateProfileString as required.
The paramseters you need to use are in help
0
KangaRooCommented:
>> I have looked into it and this seems ...
The use of ini files is not recommended by MS, butits still partof the Win32 API. Should work and don't let yourself be mislead by MS ;)
0
TallBoyCommented:
The function DOES have some differences under, but those pertain to one's writing to "system ini files," not to any other INI.

The following compiles and runs under VC++ 6.0:

-----------------------------
#include <windows.h>
#include <fstream.h>

void main( void )
{
      char strAnswer[80];

      GetPrivateProfileString(
            "master",            // Section
            "five",                  // Key
            "none",                  // Default
            strAnswer,            // Buffer
            sizeof( strAnswer ),
            "c:\\test.ini"      // Filename
            );

      cout << "The value is \"";
      cout << strAnswer << "\".\n";

}
-----------------------------


My sample INI (C:\test.ini):

-----------------------------
[master]
ten=The value of a dime
five=The value of a nickel
one=The value of a penny
-----------------------------


The output:
-----------------------------
The value is "The value of a nickel".
-----------------------------

Aside from the poor punctuation, the program works fine!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TallBoyCommented:
Argh - I edited too quickly.  The first line should read, "The function DOES have some differences when executed under NT, but..."
0
jmnolanAuthor Commented:
Thanks. The sample code worked for me. I was trying to use the CString Class instead of char[]. Caused some problems until I saw this solution.

Thanks to everyone who contributed.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.