ASCII strings are used in client and servers. However wide character strings are recomended to support verious local languages. DCOM parameters of strings are always BSTRs. So there is always a need to convert ASCII to wide char and then wide char to BSTRs. ATL framework has a set of helper macros to convert between these type of strings.

Mecro notations

Notation   

Description

A

ANSI character string.

W

Unicode character string.

T

Generic character string (equivalent to W when _UNICODE is defined, equivalent to A otherwise).

OLE

OLE character string (equivalent to W).

Mecro names

A2BSTR

OLE2A

T2A

W2A

A2COLE

OLE2BSTR

T2BSTR

W2BSTR

A2CT

OLE2CA

T2CA (Deprecated. Use T2CA_EX or CT2CA instead.)

W2CA

A2CW

OLE2CT

T2COLE

W2COLE

A2OLE

OLE2CW

T2CW

W2CT

A2T

OLE2T

T2OLE

W2OLE

A2W

OLE2W

T2W

W2T

ComBSTR class

ComBSTR is one helper class provided by MFC/ATL to convert UNICODE string to BSTR and vice versa. It has verious public methods and operators for managing and manipulating BSTRs in COM servers and client.

ComBSTR methods

NameDescription
CComBSTR::AppendAppends a string to m_str.
CComBSTR::AppendBSTRAppends a BSTR to m_str.
CComBSTR::AppendBytesAppends a specified number of bytes to m_str.
CComBSTR::ArrayToBSTRCreates a BSTR from the first character of each element in the safearray and attaches it to the CComBSTR object.
CComBSTR::AssignBSTRAssigns a BSTR to m_str.
CComBSTR::AttachAttaches a BSTR to the CComBSTR object.
CComBSTR::BSTRToArrayCreates a zero-based one-dimensional safearray, where each element of the array is a character from the CComBSTR object.
CComBSTR::ByteLengthReturns the length of m_str in bytes.
CComBSTR::CopyReturns a copy of m_str.
CComBSTR::CopyToReturns a copy of m_str via an [out] parameter
CComBSTR::DetachDetaches m_str from the CComBSTR object.
CComBSTR::EmptyFrees m_str.
CComBSTR::LengthReturns the length of m_str.
CComBSTR::LoadStringLoads a string resource.
CComBSTR::ReadFromStreamLoads a BSTR object from a stream.
CComBSTR::ToLowerConverts the string to lowercase.
CComBSTR::ToUpperConverts the string to uppercase.
CComBSTR::WriteToStreamSaves m_str to a stream.

ComBSTR operators

NameDescription
CComBSTR::operator BSTRCasts a CComBSTR object to a BSTR.
CComBSTR::operator !Returns true or false, depending on whether m_stris NULL.
CComBSTR::operator !=Compares a CComBSTR with a string.
CComBSTR::operator &Returns the address of m_str.
CComBSTR::operator +=Appends a CComBSTR to the object.
CComBSTR::operator <Compares a CComBSTR with a string.
CComBSTR::operator =Assigns a value to m_str.
CComBSTR::operator ==Compares a CComBSTR with a string.
CComBSTR::operator >Compares a CComBSTR with a string.

About our authors: Team EQA

You have viewed 1 page out of 67. Your COM/DCOM learning is 0.00% complete. Login to check your learning progress.

#