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

How can i construct BSTR with embedded NULL character in c++?

How can i construct BSTR with embedded NULL character?
Ahmed Mostafa
  • 419
  • 6
  • 16
1
vote
1 answer

Mangled LPCTSTR string returned from a function

I have two projects, A and B Project A is compiled with: 1. Standard Windows Libraries 2. Multi-byte character set 3. NO common language support Project B is compiled with: 1. MFC as a dynamic dll 2. Multi-byte character set 3. WITH using…
user236520
1
vote
1 answer

Compiling C++ code that includes results in error

I am recompiling a code from an old project that never failed me before: #include #include BSTR strToBSTR(std::string OriginalString) { char *CharString = new char[OriginalString.size() + 1]; // &OriginalString[0]; …
Tareg
  • 21
  • 2
1
vote
2 answers

How to check if a _bstr_t contains (similar to str.find) a string

I am new to _bstr_t's and still trying to get the hang of it. I was trying to check whether a particular string x is contained anywhere within the bstring. Something I would normally do like; String x = "hello"; String example = "You! hello…
pondigi
  • 856
  • 2
  • 8
  • 14
1
vote
3 answers

Converting bstr_t to double

How to do the transform bstr_t to double in c++? I was thinking to convert to *char, then *char to double?
edgarmtze
  • 24,683
  • 80
  • 235
  • 386
1
vote
2 answers

Passing a string in VBScript to a COM Function which expects a BSTR*

I calling a third-party COM function in my VBScript. The method signature is as follows: HRESULT ParseXML ([in] BSTR *textIn,[in] VARIANT_BOOL *aValidateIn,[out, retval] MSXML2.IXMLDOMDocument2 **aXMLDocOut) In my VBScript the following call gives…
Lance
  • 411
  • 2
  • 6
  • 18
1
vote
1 answer

Is it safe to pass a _bstr_t object to a function expecting BSTR as argument?

I am new to C++ so please bear with me. I know that _bstr_t is just a wrapper class for BSTR but, as seen in the MSDN documentation, _bstr_t does not have an operator to convert itself to BSTR. So can I pass a _bstr_t object to a function expecting…
1
vote
0 answers

3-Way radix quicksort for text strings ported to C++ from Java

I've ported to C++ (well, I guess mostly C) this Java 3-Way radix quicksort implementation (page 27): //Java code from the linked Princeton PDF, page 27... private static void quicksortX(String a[], int lo, int hi, int d) { if (hi - lo <= 0)…
user7340472
1
vote
0 answers

Unable to pass BSTR pointer to a COM object with Python 3.8

In my Python program, I am trying to make a call to a custom COM object written in C++. The function I'm trying to call is constructed like this: void foo( BSTR *pbstrParameters, BSTR *pbtrResult ); It is my understanding that Python converts…
saso2520
  • 11
  • 2
1
vote
2 answers

Pass BSTR from C++ DLL function to VB6 application

I have this code in my VB6 app: Private Declare Function FileGetParentFolder Lib "Z-FileIO.dll" _ (ByVal path As String) As String Output.AddItem FileGetParentFolder(FileText.Text) Output is a list, FileText is a text field containing a file path.…
Felix Dombek
  • 13,664
  • 17
  • 79
  • 131
1
vote
0 answers

BSTR allocation confusion

I am trying to call a C# library from C++. Here's the function that makes the first call: CapsReport::CapsReport(const CCOMString& reportFileName, CCDatabase* pDatabase) : m_pDatabase(pDatabase), m_pReportServer(__uuidof(ReportServer)) { …
ROBERT RICHARDSON
  • 2,077
  • 4
  • 24
  • 57
1
vote
1 answer

Memory leak in BSTR to wstring

Consider following code, Is there a memory leak in this? HRESULT GetPath(wstring &outDomainPath) { CComBSTR bstrDomainPath; AnotherGetPath(&bstrDomainPath); outDomainPath = bstrDomainPath.Detach(); } What is the difference in this?(…
snb
  • 633
  • 1
  • 6
  • 13
1
vote
1 answer

How to convert between BSTR and 32-bit Unicode strings in Visual C++?

I have 3rd party code which punycodes strings (escapes and unescapes). As Unicode input/output, it uses 32-bit Unicode strings (uint32_t-based), not 16-bit. My own input/output is BSTR (UTF 16-bit). How should I convert between 32-bit Unicode char…
Alex
  • 2,469
  • 3
  • 28
  • 61
1
vote
1 answer

Random characters from casting Arduino string to Excel BSTR through c++ DLL

So in some Arduino code I am Serial.print a few numbers like this (var1=##,var2=##,var3=##). I have a C++ DLL that I am making to get this information and Parse it into a variant array like this ("var1=",##.##,"var2=",##.##,"var3=",##.##) storing…
1
vote
1 answer

VBA/Excel, and C++ DLL, specifically problems with strings

I am working on a project for serial communications between Excel and an Arduino. The following is what I have in VBA for the reading of data from the Arduino which is where my problem lies. Private Declare Function readFromSerialPort Lib…