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

Conver QString to BSTR and vice versa

I want to convert QString to BSTR and vice versa. This is what i try to convert QString to BSTR : std::wstring str_ = QString("some texts").toStdWString(); BSTR bstr_ = str_.c_str(); and to convert BSTR to QString : BSTR bstr_; wchar_t *str_ =…
Hesam Qodsi
  • 1,569
  • 3
  • 25
  • 38
3
votes
2 answers

MS VC++ Convert a byte array to a BSTR?

I have a string that starts out in a .Net application, is encrypted and stored in AD. It's then picked up by a native C++ app and decrypted to produce an array of bytes e.g "ABCDEF" becomes 00,41,00,42,00,43,00,44,00,45 once it has been decrypted at…
user177656
  • 31
  • 1
  • 2
3
votes
2 answers

How to check if a CComBSTR starts with a certain prefix?

I'm encountering a piece of code where I need to simply do a prefix check on a given CComBSTR object (something like Y.StartsWith("X")). C++ is a bit foreign to me, and my biggest concern is efficiency. I don't need to modify the CComBSTR in any…
Shark
  • 2,322
  • 5
  • 31
  • 44
3
votes
1 answer

Can I use the _bstr_t class to convert between multibyte and Unicode on Windows? (C++)

BSTR is this weird Windows data type with a few specific uses, such as COM functions. According to MSDN, it contains a WCHAR string and some other stuff, like a length descriptor. Windows is also nice enough to give us the _bstr_t class, which…
melanie johnson
  • 597
  • 3
  • 16
3
votes
3 answers

C++ stl map: issues with BSTR

I use a map in my code bstr being the key and struct the value. Will this work or do I have to redefine something? I see no compile issues and I'm able to add elements too. However, map.find() does not work. Even though the element is…
Omi
  • 976
  • 2
  • 20
  • 35
3
votes
2 answers

Appending BSTR in a LPCSTR

I have a class function which is receving a BSTR. In my class I have a member variable which is LPCSTR. Now I need to append BSTR ins LPCSTR. How I can do that. Here is my function. void MyClass::MyFunction(BSTR text) { LPCSTR name = "Name: "; …
fhnaseer
  • 7,159
  • 16
  • 60
  • 112
2
votes
1 answer

Python String to BSTR

I am Using the iTunes COM interface on windows 7. The method iTunes.CurrentTrack.AddArtworkFromFile(path) requires path to be of type BSTR. I understand from some research that BSTR is a C++/Visual Basic data type that means basic string. Is there…
nightf0x
  • 1,969
  • 3
  • 17
  • 24
2
votes
6 answers

send a COM object with a BSTR value type in a MSMQ message

I'm trying to send a COM object over a MSMQ message in C++. This is my object : class ATL_NO_VTABLE CAnalisis : public CComObjectRootEx, public CComCoClass, public ISupportErrorInfo, public IDispatchImpl, public…
markitus82
  • 513
  • 2
  • 7
  • 18
2
votes
3 answers

Is WCHAR in COM interfaces a good thing?

Is WCHAR in COM interfaces a good thing ? I've been searching the internet for an answer to this question with no results. Basically should char* / wchar* be used in COM or should i use BSTR instead ? Is it safe or does it depend ? In this code…
Carl Serl
  • 51
  • 6
2
votes
3 answers

Pass an element from C type string array to a COM object as BSTR? (in C++)

I am writing a C++ DLL that is called by an external program. 1.) I take an array of strings (as char *var) as an argument from this program. 2.) I want to iterate through this array and call a COM function on each element of the string array. The…
Alex
  • 3,099
  • 6
  • 41
  • 56
2
votes
1 answer

How to return a BSTR which contains multiple null characters from a COM DLL

I'm creating a COM dll that can be used from PHP to read a memory mapped file whose size I already know, while I have no problem reading the file, I can't return it correctly as a BSTR. When I use the dll it only returns the characters before a null…
Caesar
  • 43
  • 7
2
votes
1 answer

C++ function returning BSTR for function that cannot call SysFreeString()

Please bear with me, i have been a c++ programmer for a little while. I need to know if i am doing this wrong. It works, but i suspect it causes a memory leak. I have this function: _bstr_t WCH2BSTR(wchar_t* st) { BSTR stres =…
Brian
  • 414
  • 4
  • 14
2
votes
1 answer

PHP - Using COM error message: Parameter 5: Type mismatch

I'm using PHP to call an object on server with class COM, at IIS 7. The object is well created, but when I'm using a method of it, PHP return this error: PHP Fatal error: Uncaught exception 'com_exception' with message 'Parameter 5: Type…
bey23
  • 313
  • 4
  • 16
2
votes
0 answers

VC 6.0 MFC How to read unicode data from sql server into CListBox

I have created a VC6.0 MFC app. I also set the project in unicode mode. But I when I load the unicode data (e.g. Russian) from sql db, I also get question mark string "????..." _variant_t TheValue; CString str; try { m_list.ResetContent(); …
justinfly
  • 179
  • 2
  • 6
2
votes
1 answer

Send a BSTR string written in a C DLL to Excel

I am trying to send a BSTR string written in a C DLL to Excel. Problem: Excel VBA receives the BSTR from the C DLL. I can see the BSTR in the VBA Intermediate window and debug window. If I try to allocate this string to a cell within a sheet, the…
12avi
  • 465
  • 1
  • 4
  • 7