bstr

How to best convert CString to BSTR to pass it as an "in" parameter into a COM method?

I need to convert a CString instance into a properly allocated BSTR and pass that BSTR into a COM method. To have code that compiles and works indentically for both ANSI and Unicode I use CString::AllocSysString() to convert whatever format CString to a Unicode BSTR. Since noone owns the returned BSTR I need to take care of it and relea...

Can I free memory passed to SysAllocString?

When allocating a new BSTR with SysAllocString via a wchar_t* on the heap, should I then free the original wchar_t* on the heap? So is this the right way? wchar_t *hs = new wchar_t[20]; // load some wchar's into hs... BSTR bs = SysAllocString(hs); delete[] hs; Am I supposed to call delete here to free up the memory? Or was that memo...

C++: Convert wchar_t* to BSTR?

I'm trying to convert a wchar_t * to BSTR. #include <iostream> #include <atlstr.h> using namespace std; int main() { wchar_t* pwsz = L"foo"; BSTR bstr(pwsz); cout << SysStringLen(bstr) << endl; getchar(); } This prints 0, which is less than what I'd hoped. What is the correct way to do this conversion? ...

BSTR, how to make your own?

I need to interface a Linux app to a server that uses bstr data. Can I "roll" my own code to make a bstr? I know the basics of a bstr, that it has a header with the byte size minus the null terminator and because of the header it can contain nulls in the middle of the string and basically all the rest of the rules that follow a bstr. I ...

How to pass string array as BSTR* to web service proxy

In VS2005 I have generated a web reference to a web service that takes a 1-dimensional array of strings ("inputArray") as an input parameter. The proxy function generated for this web service call asks for two parameters: BSTR *inputArray int inputArray_nSizeIs What is the proper syntax for passing in inputArray as a BSTR*? Currentl...

Are BSTR UTF-16 Encoded?

I'm in the process of trying to learn Unicode? For me the most difficult part is the Encoding. Can BSTRs (Basic String) content code points U+10000 or higher? If no, then what's the encoding for BSTRs? ...