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
1 answer

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…
user409091
  • 53
  • 5
2
votes
1 answer

convert ATL::CComBSTR to BSTR*

I am very new with C++. I created my C# DLL. I created Managed C++ DLL and reference it in my C# project. I want to return from C# dll a string value in a char* Problem is, I can't convert CComBSTR to BSTR ? UINT CHandler::GetData( UINT idx,…
Brita
  • 43
  • 6
2
votes
2 answers

Reverse Find pointer to nth occurrence of a character in cstring

How to Reverse Find pointer to nth occurrence of a character in cstring/BSTR? char * RFindNthOccurrence(char* src, char t, int n) { //for i/p string src = "HI,There,you,All" // and t =',' // n =2 //returned pointer should be at…
Peeyush
  • 31
  • 6
2
votes
1 answer

How to properly call IDispatch::Invoke with a required BSTR* parameter

There are many examples of how to call IDispatch::Invoke with a BSTR* parameter. I have this working with many other "SomeType*" parameter but no matter what I try, I either get HRESULT of Type Mismatch, E_OUTOFMEMORY or an access violation. It…
user3739214
  • 81
  • 1
  • 6
2
votes
3 answers

Performing a memset on struct with a BSTR

I currently have a heap corruption that is causing my application to crash. My application which is the COM server (C++) marshalls to a C# client application. It looks like a SysFreeString being called possibly from the C# side as part of a COM…
sgobiraj
  • 29
  • 2
  • 5
2
votes
2 answers

C++ Create BSTR at compile time / insert length into string at compile time?

Is it possible using macro magic or TMP to insert the length into a string at compile time? For example: const wchar_t* myString = L"Hello"; I would want the buffer to actually contain "[length] [string constant]". I'm using MSVC 2010 which lacks…
paulm
  • 5,629
  • 7
  • 47
  • 70
2
votes
2 answers

Why use CComBSTR instead of just passing a WCHAR*?

I'm new to COM. What exactly is the advantage of replacing: L"String" with CComBSTR(L"String") I can see a changelist in the COM part of my .NET application where all strings are replaced in this way. Would like to know what is the need for this.
Julian
  • 159
  • 1
  • 7
2
votes
2 answers

Qt ActiveX dynamicCall return value always empty

This is a follow up to a previous question: Qt ActiveX I am trying to use an ActiveX control in my program. QAxWidget* mAX = new QAxWidget(); mAX->setControl("{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"); I know that there is a function like the one…
Smash
  • 3,722
  • 4
  • 34
  • 54
2
votes
1 answer

Who owns returned string from _bstr_t::wchar_t*, _bstr_t::char* operators?

_bstr_t::wchar_t*, _bstr_t::char* operators return string of different types. Do I need to delete or free them? using which function?
Afriza N. Arief
  • 7,696
  • 5
  • 47
  • 74
2
votes
1 answer

MarshlDirectiveException in C# when trying to pass BSTR* from COM Component

If i call my COM-Method with something like this d.someMethod(string, doule, ref string); I get the error mentioned above. the method thats called is something like this STDMETHODIMP SomeClass::someMethod(BSTR, DOUBLE, BSTR*) As long as i dont…
Andreas
  • 51
  • 1
  • 7
2
votes
1 answer

Why BSTR and how to convert it to QString?

I'm working with a Microsoft Kinect SDK where functions return BSTR. I need to get a QString or std::string. Here's what I've tried: BSTR bstr = s->NuiUniqueId(); // QString qs((QChar*)bstr, SysStringLen(bstr)); std::wstring…
jaho
  • 4,852
  • 6
  • 40
  • 66
2
votes
1 answer

BSTR and Strings

BSTR DoSOmething() { return L""; } OR is it okay to pass TCHAR * to API taking BSTR as input parameter. Is it okay to convert wchar_t string into BSTR via a return statement.Will it cause some memory corruption?
anand
  • 11,071
  • 28
  • 101
  • 159
2
votes
2 answers

VBScript "Type Mismatch" issue with "[in, out] BSTR * " parameter

I'm working with third-party COM object that has some of its methods passing values back as BSTR pointer. Since VBscript supports only Variant type attempts to use in a way like Object.Method(sMyString) reasonably end with "Type mismatch" error. I…
Albert Gareev
  • 790
  • 6
  • 13
2
votes
3 answers

Reading single chars from a .NET SecureString in C#?

WPF's PasswordBox returns a SecureString, which hides the password from snoopers. The problem is that you eventually have to get the value of the password, and the suggestions I've found on the net all involve copying the value into a string, which…
Jeff Dege
  • 11,190
  • 22
  • 96
  • 165
2
votes
4 answers

Store BSTR in a std::vector?

I have an ATL COM component method which takes a BSTR as an in parameter. I need to add each call to this method in an array. I can't use a SAFEARRAY as that is fixed size so I was thinking that std::vector would be the easiest choice. Of course I…
Jonnster
  • 3,094
  • 5
  • 33
  • 45