Combine Buffers -How To?

Hi all,

I'm really not at all experienced with C++, but I have some changes to make in code that used to be maintained by someone else. The code that exists may not be the best, but I'm not looking to totally re-write the widget because it works for us with no problems to date.

Anyway, here is the current code... I'll put the psuedo code or what I would like to do in << >>. or commented //..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
DWORD NumOfBytes = 0;
<<DWORD NumOfBytes2 = 0;  // Don't know if this second NumOfBytes is needed or if first can be used twice>>
char Buf[1024];
<<char Buf2[1024];>>
char *pNextSetting = NULL;
CString str;
CPlugIn *pPlugIn;


NumOfBytes = GetPrivateProfileSection("OurApp Update PlugIns", Buf, 1024, m_IniPath);
<<NumOfBytes2 = GetPrivateProfileSection("OurApp Update PlugIns", Buf2, 1024, m_OldIniPath);>>

// Below is the current line of code, but I would really like this to become something like...
// pNextSetting = Buf + Buf2

pNextSetting = Buf;

//So, how do I combine the two buffers?

str = pNextSetting;
if (NumOfBytes > 0) {
	while (*pNextSetting != 0x00) {
		pPlugIn = new CPlugIn;

		pPlugIn->Id = str.Left(str.Find("="));
		pPlugIn->Version = str.Right(str.GetLength() - str.Find("=") - 1);

		m_LocalPlugIns.SetAt(pPlugIn->Id, pPlugIn);

		pNextSetting = pNextSetting + strlen(pNextSetting) + 1;
		str = pNextSetting;
	}
}


Again, it may not be the best and its older code, but it works so I'm hoping there isn't much rework needed to combine what I'm pulling from .ini files.

Any help is MORE THAN APPRECIATED!!
it depends what you mean by "combine". How exactly do you want 'pNextSetting' to look?

For example, let's say you have the following:

Buf = "abc";
Buf2 = "def";

Would you want pNextSetting to be "abcdef"? Or "abc\0def" (with a null terminator between each string)?
Hmm, I'mnot really sure what the formatting is.

The data that is pulled from the .ini is in the form of...

{Windows-Installer-Product-Code}=ProductVersion of .msi.

Does that help or not really?
So then you want to create two different CPlugIns. One for the old inipath and one for the new one. Is that right?

That wouldn't be accomplished by combining the buffers. It'd be accomplished by running the code twice (once for each string).

I'd show an example, but I have to head out to work now so I don't have time (plus I'm not entirely sure that's what you're looking for).

If I have time at my break and if nobody has replied yet I'll try to give an update.
Thanks! I look forward to any examples!! :D
What I'm thinking I want is one CPlugIns that contains information from both Ini files.
Here is what I did and it appears to work...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
DWORD NumOfBytes = 0;
//Added new and increased Buf size...
DWORD NumOfBytes2 = 0;
char Buf[2048];
char *pNextSetting = NULL;
CString str;
CPlugIn *pPlugIn;


NumOfBytes = GetPrivateProfileSection("OurApp Update PlugIns", Buf, 2048, m_OldIniPath);
NumOfBytes2 = GetPrivateProfileSection("OurApp Update PlugIns", Buf+NumOfBytes, 2048, m_IniPath);

pNextSetting = Buf;
	
str = pNextSetting;


Then I changed my condition to NumOfBytes2 > 0 from NumOfBytes > 0...

1
2
3
if (NumOfBytes2 > 0) {
	while (*pNextSetting != 0x00) {
		pPlugIn = new CPlugIn;  //etc, etc, etc..... 
I think I had to change the condition to (NumOfBytes > 0 || NumOfBytes2 > 0). Seems to be right in my testing so far. My fingers are crossed, however.
Topic archived. No new replies allowed.