Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top