Click here to Skip to main content
15,900,906 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Working with INI Related functions Pin
swaapu2-Feb-06 22:39
swaapu2-Feb-06 22:39 
GeneralRe: Working with INI Related functions Pin
_anil_2-Feb-06 23:34
_anil_2-Feb-06 23:34 
GeneralRe: Working with INI Related functions Pin
swaapu5-Feb-06 20:12
swaapu5-Feb-06 20:12 
GeneralRe: Working with INI Related functions Pin
alleyes24-Jul-09 4:45
professionalalleyes24-Jul-09 4:45 
AnswerRe: Working with INI Related functions Pin
Jagadeesh VN2-Feb-06 20:34
Jagadeesh VN2-Feb-06 20:34 
GeneralRe: Working with INI Related functions Pin
swaapu2-Feb-06 20:43
swaapu2-Feb-06 20:43 
GeneralRe: Working with INI Related functions Pin
Jagadeesh VN2-Feb-06 20:51
Jagadeesh VN2-Feb-06 20:51 
AnswerRe: Working with INI Related functions Pin
John R. Shaw2-Feb-06 21:59
John R. Shaw2-Feb-06 21:59 
Using INI files is one of the simpilist things in the world. If you read the documentation, you'll note that the names returned by GetPrivateProfileSectionNames() are each null terminated, that means when you pass it to GetPrivateProfileSection(), it only sees the first one in the list. You need to take into account the return value of GetPrivateProfileSectionNames(), which is the number of characters retreived, and parse it to get each section name.
Example of what GetPrivateProfileSectionNames() should return: "SECTION1\0SECTION2\0SECTION3\0\0".

The same applies to what is returned by GetPrivateProfileSection(). In your case the buffer should actualy contain something like: "KEY1=500\0KEY2=VALUE\0\0". This is anouther case where you need to pay attention to the return value, and manualy parse buffer.

Some Notes:
1) There are other functions that read the specific values given the section and key names, they are easier to use. This assumes that your program already knows the section names and the key names.
2) After the first call the .INI is loaded into memory, so there is almost no overhead associated with reading the file on subsiquent calls. Because it is already loaded into memory space.
3) Your code is written in 'C' not 'C++', so you should provide a define statement ("#define") that specifies the maximum size of the buffer. That way you can change it by simply changing the value defined. In this case you do have a second option, if you dinamicaly allocate the buffer and the value return is rediculously high, then the value returned is actualy the negitive size of the required buffer. The only reason that it is rediculoulsy high, is that both functions return a DWORD, which is unsigned. If you take that value and convert it to a long and subtract it from 0, then you should have the required number of bytes needed to hold all the data, at which point you can reallocate the buffer and recall the function.

What all the above amounts to, is that you need to read and understand the documentation, before you use the functions. It also means that I have never had a reason to use those two particular functions, because of note 1.

I hope you understand what I said, because it is very important that you understand what I consider the fundamentals of programming. After a while you'll be seeing these things in your sleep.

Good Luck,
John R. Shaw

INTP
Every thing is relative...
QuestionRun-Time Check Failure #3 Pin
newbie53452-Feb-06 20:15
newbie53452-Feb-06 20:15 
AnswerRe: Run-Time Check Failure #3 Pin
John R. Shaw2-Feb-06 23:19
John R. Shaw2-Feb-06 23:19 
GeneralRe: Run-Time Check Failure #3 Pin
newbie53453-Feb-06 11:12
newbie53453-Feb-06 11:12 
QuestionDrag and Drop Pin
Anil_vvs2-Feb-06 19:58
Anil_vvs2-Feb-06 19:58 
AnswerRe: Drag and Drop Pin
Prakash Nadar2-Feb-06 20:02
Prakash Nadar2-Feb-06 20:02 
GeneralRe: Drag and Drop Pin
Anil_vvs2-Feb-06 20:03
Anil_vvs2-Feb-06 20:03 
GeneralRe: Drag and Drop Pin
Anil_vvs2-Feb-06 20:14
Anil_vvs2-Feb-06 20:14 
AnswerRe: Drag and Drop Pin
Jagadeesh VN2-Feb-06 20:14
Jagadeesh VN2-Feb-06 20:14 
GeneralRe: Drag and Drop Pin
Anil_vvs2-Feb-06 20:17
Anil_vvs2-Feb-06 20:17 
QuestionWhat is the proper way to implement this? Pin
LeeeNN2-Feb-06 19:53
LeeeNN2-Feb-06 19:53 
AnswerRe: What is the proper way to implement this? Pin
Jagadeesh VN2-Feb-06 20:08
Jagadeesh VN2-Feb-06 20:08 
QuestionResizing Dialog and Controls Pin
omrao2-Feb-06 19:19
omrao2-Feb-06 19:19 
AnswerRe: Resizing Dialog and Controls Pin
Jagadeesh VN2-Feb-06 20:19
Jagadeesh VN2-Feb-06 20:19 
AnswerRe: Resizing Dialog and Controls Pin
ThatsAlok3-Feb-06 4:39
ThatsAlok3-Feb-06 4:39 
QuestionNeed Help in Project Pin
cookie7892-Feb-06 18:09
cookie7892-Feb-06 18:09 
AnswerRe: Need Help in Project Pin
Jagadeesh VN2-Feb-06 18:56
Jagadeesh VN2-Feb-06 18:56 
AnswerRe: Need Help in Project Pin
John R. Shaw2-Feb-06 19:42
John R. Shaw2-Feb-06 19:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.