There are several win32 functions that require the use of a string with embedded
NULLs and are terminated with an extra NULL (i will call them DZ strings for short).
An example of such a DZ string: “part1 part2 part3 ”.
To name just a few of functions that work with DZ strings:
As most string-functions (strcmp, strchr etc) expect a zeroterminated string, they are of little use when
you have to parse a DZ string.
The CString class could be used to manipulate them, but you must be carefull not to call the non-DZ-aware
CString-methods (such as Right(), Mid(), Left(), Replace() and Find()).
I decided to create a class that helps constructing and parsing those DZ strings.
The class is called CDoubleZeroString and is not derived from CString.
An example how to use this class:
dz.Add(“a=1”); // add a zeroterminated ‘part’
// operator(const char*) will return “a=1 b=2 c=3 ”
WritePrivateProfileSection(“humbug”, dz, “.\humbug.ini”);
GetPrivateProfileSection(“humbug”, buffer, sizeof buffer, “.\humbug.ini”);
// cleanup dz
// AddDoubleZero will parse buffer
// print the outcome
cout << dz.Get(i) << endl;
CString test = dz;
cout << “cstring ” << test << endl;
This will show the following output:
The CString test will only copy the first substring when it is constructed…
If you want to implement this using CString you would have to do something like:
CString dz(“a=1 ” “b=2 ” “c=3 ” “