<!-- Download Links -->
<!-- Add the rest of your HTML here -->
There are several classes available that handle
BSTR strings, however I have yet to find
one that offers basic buffering support. The
CBSTRStream class was designed to provide
this feature as well as some useful data type conversion functions.
This class is not a replacement for the popular
_bstr_t class, but it is designed
to interoperate with it.
This class is very easy to use (as the examples below will show you). You
simply use the << operator to append data to the stream.
The list at the end of the article provides a more detailed overview.
Example 1 (basic usage):
_bstr_t bstrData2(L"some other data");
GUID guid =
long nData = 3;
bsData << bstrData << L"TEST" << nData << L" " << bstrData2 << L" " << guid;
Example 2 (composing SQL queries):
long nItemId = 1;
bsSelect << L"SELECT It_Name, It_Desc FROM It_Item WHERE It_Id = " << nItemId;
Example 3 (using allocation hints):
long nData = 14;
long nData2 = 18;
long nData3 = 25;
CBSTRStream bsData(10, 5);
bsData << L"Numbers: " << nData << L", " << nData2;
bsData << L", " << nData3;
CBSTRStream(const CBSTRStream& bsSrc, long nInitialBufferSize = 50, long nChunkSize = 50)|
CBSTRStream(long nInitialBufferSize = 50, long nChunkSize = 50)
These constructors provide you with the opportunity to set allocation hints
for the stream allocator. The nInitialBufferSize sets the size used during the first buffer allocation
and the nChunkSize sets the size appended during the next buffer reallocations.
CBSTRStream& operator << (const _bstr_t& bstrData)|
CBSTRStream& operator << (wchar_t* pstr)
CBSTRStream& operator << (REFGUID src)
CBSTRStream& operator << (long nData)
CBSTRStream& operator << (unsigned long nData)
CBSTRStream& operator << (int nData)
CBSTRStream& operator << (double dValue)
CBSTRStream& operator << (const CBSTRStream& bsSrc)
These operators provide basic stream support as well as data type conversions.
They will append the string representation of their respective data type to the stream.
Compares two |
Assigns a new value to an existing |
Extracts the pointers/objects to the encapsulated |
Resets the string (but keeps the buffer).
|long length const|
Returns the length of the encapsulated BSTR.
- This class is NOT threadsafe.