views:

392

answers:

2

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.

+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
+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
But does CString handle embedded NULs the same way that BSTR does?
Constantin
Yes. CString handless NULLs just fine.
Franci Penov