Questions tagged [bstr]

`BSTR` stands for "Basic String". It is a size-prefixed, fixed-length, null-terminated, UTF-16 encoded character array used heavily in Microsoft's COM and OLE technologies for marshalling strings, especially between languages.

In many (but not all) cases BSTRs can be used in place of standard wide character arrays, but in almost all cases the reverse is not true.

For a complete guide to BSTR semantics, see Eric's Complete Guide to BSTR Semantics.

179 questions
1
vote
1 answer

operator TYPE () and taking the address of an object

The ATL class CComBSTR has a BSTR member m_str and an operator BSTR () which returns m_str. Now, if a function takes a BSTR * as argument, is it ok to pass the address of a CComBSTR? CComBSTR path; // signature is IzFileFinder::GetDir(CY index,…
Felix Dombek
  • 13,664
  • 17
  • 79
  • 131
1
vote
4 answers

ComBSTR assignment

I'm confused about COM string assignments. Which of the following string assignment is correct. Why? CComBSTR str; . . Obj->str = L"" //Option1 OR should it be Obj->str = CComBSTR(L"") //Option2 What is the reason
Julian
  • 159
  • 1
  • 7
1
vote
2 answers

Is garbage initial value okay for `[out] BSTR*` parameter?

According to MSDN: For [out] parameters, the method or property allocates the memory and the caller is responsible for freeing the memory. Which of these are okay: [...] STDMETHOD(Method)([out] BSTR* psValue) [...] BSTR…
Afriza N. Arief
  • 7,696
  • 5
  • 47
  • 74
1
vote
1 answer

When is it optional to reallocate `[in,out]` parameter?

If I have [in,out] BSTR* parameter and I want to modify the string content but still maintain the same length, can I just reuse it or do I need to realloc/free-and-alloc the BSTR? MSDN says: For [in, out] parameters, the caller allocates memory,…
Afriza N. Arief
  • 7,696
  • 5
  • 47
  • 74
1
vote
1 answer

c++ _bstr_t instead of use string

I have some code to read file,but it is used std::string, i need to use _bstr_t the code follow can works fine. how to change the type? std::ifstream inFile("QdatPassWordconfig.config"); std::string sPassWord; //(here, i need to use _bstr_t) …
jack.li
  • 973
  • 1
  • 9
  • 20
1
vote
1 answer

Do MSXML methods take memory ownership of their BSTR parameters?

Do MSXML methods take memory ownership of their BSTR parameters? For example: load, getElementsByTagName, or selectSingleNode I'am asking this because I saw codes that simply call CString's AllocSysString() and pass it to MSXML methods without…
Afriza N. Arief
  • 7,696
  • 5
  • 47
  • 74
1
vote
2 answers

Problems converting BSTR to char *

We've an old C++ app that's making calls to third-party webservices, using WinHttp.WinHttpRequest.5.1. I won't list all of the details of the call sequence, as I don't think it's relevant to the problem, but we finish by calling hr =…
Jeff Dege
  • 11,190
  • 22
  • 96
  • 165
1
vote
2 answers

Convert LPCOLESTR to BSTR?

Any ideas on how to make a BSTR out of an LPCOLESTR? Silly thing to get hung up on..
Leo
1
vote
1 answer

Invalid null pointer when using _bstr_t

I have a COM DLL that I am developing and I am running into a few issues. I have a try catch around a block of code and in the catch I get a _bstr_t from the exception. What I wanted to do was catch that exception and print it out to a string,…
Seb
  • 3,414
  • 10
  • 73
  • 106
1
vote
1 answer

CComBSTR memory management

I am using CComBSTR in below scenario, void MyDlg::OnTimer() { ...... CComBSTR statusString1 = ::SysAllocString(_T("Test")); .... } The timer will get executed with in each 5 seconds interval. In the above case the meory is…
srajeshnkl
  • 883
  • 3
  • 16
  • 49
1
vote
1 answer

Freeing up _bstr_t which is created from char*

I have char* array and I am dynamically allocating memory for it. char *strData = new char[length+1]; This char* I am passing to _bstr_t as below, _bstr_t bstrData = strData; How to free up the memory allocated for the char* through bstrData ?
srajeshnkl
  • 883
  • 3
  • 16
  • 49
1
vote
2 answers

C: int to _bstr_t

im trying to draw series of plots in excel using c. The problem is when i try to put making of plots in loop, i must change name of worksheets in excel. But those names are in _bstr_t format: pSheet->Name =name; I want to make name look…
speedyTeh
  • 247
  • 1
  • 8
  • 22
1
vote
1 answer

How can I set the length, when creating a BSTR (using _bstr_t wrapper) by a native string?

When creating a BSTR (using _bstr_t as wrapper class) I have to use some of the constructors of _bstr_t. Since a BSTR is a length prefixed string that may contains null-characters, there must be a possiblity to create such a string using a native…
Christoph Meißner
  • 1,511
  • 2
  • 21
  • 40
1
vote
2 answers

BSTR to CString conversion for Arabic text

My VC++ (VS2008) project uses Multi-byte Character set. I've the following code to convert a date string to COleDateTime _bstr_t bstr_tDate = bstrDate; //bstrDate is populated by a COM function const CString szStartDateTime = bstr_tDate.operator…
Karthik Murugan
  • 1,429
  • 3
  • 17
  • 28
1
vote
2 answers

Handling BSTRs on MacOSX in C

I've written some code in C for converting strings passed from VBA, when the C code is called from VBA from a MacOSX dylib. I got some good hints here, and since I only care about ASCII strings I've written the following functions to convert the…
Martin
  • 146
  • 7