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

Does a BSTR passed by reference need re-allocation in the calling function?

BSTR newID_x = SysAllocString(L"newID"); BSTR newX_x = SysAllocString(L"newX"); functionA(&newID_x); //Func A does some operation on newID_x, we have that value in newID_x now functionA(&newX_x); //After Func A is called for the second time, both…
ammar
  • 1
0
votes
1 answer

VarBstrFromI4 changes the value of some other BSTR in the program

BSTR length; BSTR checkLength = SysAllocString(TEXT("document.getElementsByTagName('tspan').length.toString()")); HRESULT h = gWebView->stringByEvaluatingJavaScriptFromString(checkLength, &length); SysFreeString(checkLength); long longLength; h =…
ammar
  • 1
0
votes
0 answers

Can I profile memory allocated in external dll in C# (e.g. with Visual Studio)

Is there a way to profile memory allocated in an external DLL, in my case the SysAllocString function? The DLL is compiled from Delphi and I have control over both the Delphi and C# code if instrumentation needs to be written. In the overview of the…
JoBe
  • 33
  • 6
0
votes
1 answer

c++ dtor to free _bstr_t memory

A simple question but I am not sure what it is done in C++. When I have a class that have _bstr_t member. I would like to know if does member are freed when the object is deleted: class A { _bstr_t foo("Testing"); } The A class does not have a…
mathk
  • 7,973
  • 6
  • 45
  • 74
0
votes
2 answers

Language for non-unicode programs change ini reading

I've a non-unicode application which is using unicode versions of the ini reading functions like GetPrivateProfileSectionW and GetPrivateProfileStringW. The program is working well when "Language for non-unicode programs" is set to English. When I…
0
votes
1 answer

converting a char* to BSTR* which contains special characters

I'm trying to convert a char* to a BSTR*, and my char* has special characters in it from being encrypted. I have tried several approaches found on the web, but back in the calling vb code, I always end up with something different. I'm pretty sure…
George
  • 1
0
votes
1 answer

Passing strings in / out of Delphi COM Server

I've tried several variations of the code below with returning HRESULT (which is the preferable COM standard) or returning BSTR. I've tried other datatypes as well. I usually get a "missing implementation of interface method" compile error, but when…
Kevin S. Miller
  • 913
  • 1
  • 9
  • 21
0
votes
3 answers

Can I call VariantChangeType on an input BSTR VARIANT?

I have a COM object written in C++ with a method using the following signature. Assume that the variant contains a BSTR (just VT_BSTR, not VT_BYREF | VT_BSTR). HRESULT myfunc(/*[in]*/ VARIANT param) I want to change the type to something else. If…
jveazey
  • 5,398
  • 1
  • 29
  • 44
0
votes
3 answers

How to convert CComVariant bstr to CString

I'm a newbie with C++ and I've taken over a COM project to fix some issues. The current issue I'm working on is handling UTF8 strings. I have this piece of code: // CString strValue; CStringW strValue; CComVariant* val =…
Paul Meems
  • 3,002
  • 4
  • 35
  • 66
0
votes
1 answer

Can't get exact position of BSTR data in VARIANT struct

I have strange problem with reading BSTR value from a VARIANT struct. I use following Javascript code to send data to C++ code: external.CppCall("zhttShow", 1, "Y"); In an Invoke function in my C++ code, I tried to access that data: HRESULT…
NoName
  • 7,940
  • 13
  • 56
  • 108
0
votes
2 answers

Remove chr(0) from (c++ BSTR) string in VBA

I've written a c++ function in a DLL which exports a string to a VBA program: BSTR _stdcall myFunc() { CRegKey Key; CString sValue; BSTR Str; LONG nA = Key.Open(HKEY_LOCAL_MACHINE, _T("[group path goes here]"), KEY_READ); ULONG…
Noldor130884
  • 974
  • 2
  • 16
  • 40
0
votes
1 answer

C++ code for concatanation of two Bstr strings

I am trying to concatenate two bstr_t one is char '#' and the other is an int (which I convert it to bstr_t) and gonna return it as a bstr (e.g '#'+'1234' as '#12345'). however, after concatenation the final result only contains '#'. I don't know…
0
votes
1 answer

Marshalling ref IntPtr to BSTR * in C#

I am trying to call a function which allocates memory for the string and then does something with the string. Here is the basic example which illustrates the problem: C++: STDMETHODIMP CFunctionsCollection::Function2 ( BSTR leftString,…
Vladimir
  • 1
  • 1
  • 1
0
votes
2 answers

How would I call a legacy C++ DLL interface method, with params BSTR* and BSTR** from C#

Good Day fellow developers I have been searching the internet for 2 days now on how to do what I need and I have tried a lot of samples with no success. However, that does not mean I covered all sites - I am thinking I am blind in one eye and…
0
votes
0 answers

ADSystemInfo.UserName bstr to string

I need to execute a logon script where I need to check if the user belongs to a OU specific. I get the DN: Dim objSysInfo, objUser Set objSysInfo = CreateObject("ADSystemInfo") strUserDN = objSysInfo.UserName And then I use the InStr function to…
kintela
  • 1,283
  • 1
  • 14
  • 32