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
4
votes
2 answers

Delete a FolderItem

I want to delete a file stored in an USB flashdrive (actually an android device's sd card). I ask the user to point the app's folder inside the sd card, and i hold a Shell32.Folder object pointing to it. I can iterate between the files (FolderItem…
Marcelo Vitoria
  • 591
  • 1
  • 5
  • 15
4
votes
1 answer

How to properly reset _bstr_t to `NULL`

In the snippet bellow (simplified scenario of a loop) _bstr_t original(OLESTR("MyString")); // ref-count = 1 _bstr_t another; another = original; // ref-count = 2 // do something with another another.Assign(NULL); // expected: ref-count = 1, and…
Afriza N. Arief
  • 7,696
  • 5
  • 47
  • 74
4
votes
4 answers

_bstr_t memory leak

I have a c++ code. But it is not releasing memory properly. Tell me where I am wrong, here is my code 1 void MyClass::MyFunction(void) 2 { 3 for (int i=0; i
fhnaseer
  • 7,159
  • 16
  • 60
  • 112
4
votes
5 answers

Getting a char* from a _variant_t in optimal time

Here's the code I want to speed up. It's getting a value from an ADO recordset and converting it to a char*. But this is slow. Can I skip the creation of the _bstr_t? _variant_t var = pRs->Fields->GetItem(i)->GetValue(); …
Corey Trager
  • 22,649
  • 18
  • 83
  • 121
3
votes
1 answer

COM fail to properly marshal a BSTR from a managed server to native client

I'm struggling with a scenario where I have a managed interface exposed through COM and consumed by a native client. I've managed to isolate the problem and it basically boils down to a string being improperly marshalled by the interop runtime, to…
Karim Agha
  • 3,606
  • 4
  • 32
  • 48
3
votes
2 answers

How does it convert _bstr_t to BSTR when passing as an argument?

Taking a simple example: _bstr_t smartString(L"MyString"); Process(smartString); // takes BSTR. Initially I thought _bstr_t has a BSTR operator converting from _bstr_t to BSTR, but looking at msdn there is no such operator defined. How does it…
AksharRoop
  • 2,263
  • 1
  • 19
  • 29
3
votes
2 answers

how to test if CComBSTR is empty

How to test if a CComBSTR is an empty string? (with no 'text' value, can be "" or can be null) my ideas: test if CComBSTR::ByteLength() returns 0 test if CComBSTR::GetStreamSize() returns 0 test if CComBSTR::m_str is NULL test if CComBSTR::Length()…
Hayri Uğur Koltuk
  • 2,970
  • 4
  • 31
  • 60
3
votes
1 answer

Pass .NET SecureString to COM Interop

How do you manually marshal a BSTR from .NET to COM? I am trying to pass a secret stored in a SecureString from my .NET application to a method on a COM object. I want to avoid converting the SecureString to a String because that's not how you're…
Daniel Schilling
  • 4,829
  • 28
  • 60
3
votes
2 answers

Qt5 MinGW undefined reference to ConvertStringToBSTR

My link error: Qt\Tools\mingw530_32\i686-w64-mingw32\include\comutil.h:278: erreur : undefined reference to `_com_util::ConvertStringToBSTR(char const*)@4' Actually in .pro file: LIBS += -lws2_32 -lwbemuuid -lole32 Which lib to add? lib comsuppw?…
mabro
  • 61
  • 7
3
votes
1 answer

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…
Dixon Steel
  • 1,021
  • 4
  • 12
  • 27
3
votes
1 answer

_bstr_t Not a known identifier

I've been using this class for years and it's always "just there". I created a new project the other day and without explicitly doing anything, this class was available. Now another new project complains it is not known. Both projects have the same…
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
3
votes
4 answers

Why Microsoft CRT is so permissive regarding a BSTR double free

This is a simplified question for the one I asked here. I'm using VS2010 (CRT v100) and it doesn't complain, in any way ever, when i double free a BSTR. BSTR s1=SysAllocString(L"test"); SysFreeString(s1); SysFreeString(s1);
mbelaoucha
  • 85
  • 6
3
votes
5 answers

Why is BSTR length prefix 4 bytes on 64-bit platforms?

It seems that on 64-bit platforms it would be reasonable to have a 8-byte length prefix. If we can address more than 4Gb of mem why not allow, say, 5Gb strings? Is the answer just "by specification" or there is some interoperability/backwards…
Alexander Chertov
  • 2,070
  • 13
  • 16
3
votes
2 answers

When using W2A to convert BSTR to std::string, is there any clean up needed?

Code looks like the following: class A { public: std::string name; }; A a; CComBSTR textValue; // some function which fills textValue a.name = W2A(textValue); Now, I've used CComBSTR so I don't have to dealloc the BString, but does W2A…
bpeikes
  • 3,495
  • 9
  • 42
  • 80
3
votes
3 answers

Why doesn't COM use a static empty BSTR?

When allocating an empty BSTR, either by SysAllocString(L"") or by SysAllocStringLen(str, 0) you always get a new BSTR (at least by the test I made). BSTRs aren't typically shared (like Java/.NET interment) since they are mutable but an empty string…
Motti
  • 110,860
  • 49
  • 189
  • 262
1 2
3
11 12