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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
TallBoyConnect With a Mentor Commented:
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
 
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:
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
All Courses

From novice to tech pro — start learning today.