I have several projects where I need to append strings to a BSTR/CComBSTR/_bstr_t object (e.g. building a dynamic SQL statement). Is there an out-of-the-box type in the WinAPI to buffer the concatenation (like StringBuilder in .NET), or do I have to write my own? From what I know about the append methods, they perform re-allocation.
views:
392answers:
2
+1
A:
You have to write your own. You can use the SysAllocStringLen, or SysReallocString APIs to get different-sized buffers. They work on an input string, but you can pass NULL to allocate a fixed-size, uninitialised buffer.
gbjbaanb
2008-09-26 14:46:53
+2
A:
Copy the BSTR into a CString, do all the modifications there and then copy it back into the BSTR/CComBSTR. CString's allocations are faster than SysAllocStringLen.
Franci Penov
2008-09-26 15:04:27
But does CString handle embedded NULs the same way that BSTR does?
Constantin
2009-05-01 22:45:00
Yes. CString handless NULLs just fine.
Franci Penov
2009-05-05 20:22:09