Buffer Pointer To Makes Sense

Here we go again. I've done this before, or something similar, anyway, but I can't re-figure out how to do it...

I'm trying to get the tag values of an ini file into a buffer by using GetPrivateProfileSection() so I can display the data in a combo box. I can't figure out how to set up the buffer so I can structure this properly. Here is the link so you can see what I want to do...

http://msdn.microsoft.com/en-us/library/ms724348(v=VS.85).aspx

My problem is with the second paramenter, the "lpszReturnBuffer" in the msdn link above.

No matter how I declare it, when I run it through the debugger the string is empty.

At this point I just want to get data in the string. I believe I can figure out how to parse the data once I get the info into it, but how to do just that is my problem.

Of course, you will have to set up an INI file with at least one section and several tags to try it yourself, but I'm sure you have a few of those laying around.
Last edited on
Can you post the code you're trying?

EDIT:
This seems to work.

1
2
3
4
5
6
7
8
9
10
TCHAR name[] = L"SectionName";
TCHAR retStr[100];
DWORD size = 100;
TCHAR fname[] = L"C:\\path\\to\\ini";

DWORD ret = GetPrivateProfileSection(
	name,
	retStr, 
	size,
	fname);
Last edited on
If I use your example, only I do this with the string --

char lpData[32767];

... and then call GetPrivateProfileSection(), my lpData string shows as not picking up anything when I do a run to cursor.

Keep in mind that the INI files has this structure --

[SECTION_NAME]
tag_name_01=tag_data_01
tag_name_02=tag_data_02

and so on. If I am reading the MSDN info correctly, then the LPSTR lpData string should be picking up BOTH the "tag_name_01" string and also the "tag_data_01" string.

So in the first place, I'm not getting anything in the main string by doing it your way, but also, I need to find a way to parse out each tag/tag combo.

My main problem right now is declaring the string properly. I can't see your way as working, nor does it when I run through the debugger using run to cursor.
I have discovered that I am getting the FIRST ini tag of the ini file when I use the straight char lpData[32767] declaration.

If I try it with a loop, or some other way, I still get ONLY the first tag line of the ini file.

For example, using my above demo, the string reports back using MessageBox() that "tag_name_01" is the data that was retrieved from the INI file. No matter what I have tried, I cannot get to "tag_name_02".

Does that make sense?

If you go back and read the MSDN article, it states that each line of the INI file that is put into the string has an ending NULL character, and that the very end of the INI file as TWO ending NULL chars. I suspect this has something to do with it.
Last edited on
Okay, I THINK the problem lies with my parsing of the string. By declaring --

char lpData[32767];

and then calling the GetPrivateProfileSection() function, and then by iterating through lpData with another string, it IS returning info later down in the INI file, which I am trying to put one line at a time into another string so I can add the data to a combo box.

So the problem appears to me not parsing the string correctly at this point, not declaring the string.
Last edited on
I figured out most of it. Still a few minor quirks, but the upshot is, it won't work unless you use the '\0' as in the following example --

if(lpData[iCount]=='\0')...

If you try to use the '\n' or '\r' or '\r\n' or even if you do a straight --

if(lpData[iCount]==0)...

then it won't work. To iterate though the main lpData string, you MUST employ the '\0' syntax or it will just blow right through your loop without ever recognizeing anything.

That little item was where the main culprit was, right there.
Topic archived. No new replies allowed.