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 //..

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!!

Assuming the buffers contain binary, not string, data -- create a third buffer that is large enough to hold both the first and second buffers, e.g. char buf3[2048]; Then use memcpy() to copy each of the two original buffers into the third buffer.

If the two buffers actually contain null-terminated strings then the job is a lot simpler. std::string b3 = buffer1; b3 += buffer2;

Edited 6 Years Ago by Ancient Dragon: n/a

The problem for me is I don't know what the data looks like in the buf. It is a pull of an INI sections values that will be in the form of

1{Windows-Installer-Product-CodeGuid}=ProductVersion (in #.#.# format)

Here is what I did and it appears to work...

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...

if (NumOfBytes2 > 0) {
	while (*pNextSetting != 0x00) {
		pPlugIn = new CPlugIn;  //etc, etc, etc.....
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.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.