Главная страница | назад





Article #17513: BSTRs as Params instead of AnsiString

 Question and Answer Database
FAQ2513C.txt BSTRs as Params instead of AnsiString
Category :ActiveX
Platform :All
Product :C++Builder 3.x
Question:
I have upgraded from BCB1 to BCB3. In BCB1. The functions
in one of the ActiveX controls that used to take a AnsiString now
take a BSTR. I tryed using it the same way as i used to with an
ansistring, but this does not work. I also tryed typecasting the
parameter to a wchar_t* and that crashes the system. What do I
do?
Answer:
v3.0 exposes VT_BSTR as true BSTRs since we now support
Server code and an AnsiString cannot be used for an [out] or
[out,retval] string parameter.
You'll need to use a WideString for the call:
(WideString is a Pascal Runtime Type that will work in
C++Builder. For more information on WideString look at
vcl\wstring.h)
The reason that typecasting using a wchar* crashed the system
is because with BSTR's you need to use SysAllocString and
SysFreeString, otherwise you will crash the app.
7/2/98 10:32:32 AM

Last Modified: 01-SEP-99