Previous Table of Contents Next


18.3.4 Mapping for String Types


   COM support for strings includes the concepts of bounded and unbounded strings. Bounded strings are defined as strings that have a maximum length specified, whereas unbounded strings do not have a maximum length specified. COM also supports Unicode strings where the characters are wider than 8 bits. As in OMG IDL, non-Unicode strings in COM are NULL-terminated. The mapping of COM definitions for bounded and unbounded strings differs from that specified in OMG IDL.

    Table 18-8 illustrates how to map the string data types in OMG IDL to their corresponding data types in both Microsoft IDL and ODL.

   Table 18-8 Microsoft IDL/ODL to OMG IDL String Mappings

Microsoft IDL

Microsoft ODL

OMG IDL

Description

LPSTR [string,unique] char * LPSTR, string Null-terminated 8-bit character string
BSTR BSTR wstring Null-terminated 16-bit character string
LPWSTR [string,unique] char * LPWSTR wstring Null-terminated Unicode string

   If a COM Server returns a BSTR containing embedded nulls to a CORBA client, a E_DATA_CONVERSION exception will be raised.

   18.3.4.1 Mapping for unbounded string types

   The definition of an unbounded string in Microsoft IDL and ODL denotes the unbounded string as a stringified unique pointer to a character. The following Microsoft IDL statement

   // Microsoft IDL typedef [string, unique] char * UNBOUNDED_STRING;

   is mapped to the following syntax in OMG IDL.

   // OMG IDL typedef string UNBOUNDED_STRING;

   In other words, a value of type UNBOUNDED_STRING is a non-NULL pointer to a one-dimensional null-terminated character array whose extent and number of valid elements can vary at run-time.

   18.3.4.2 Mapping for bounded string types

   Bounded strings have a slightly different mapping between OMG IDL and Microsoft IDL. Bounded strings are expressed in Microsoft IDL as a “stringified nonconformant array.? The following Microsoft IDL and ODL definition for a bounded string:

   // Microsoft IDL and ODL const long N = ...; typedef [string, unique] char (* BOUNDED_STRING) [N];

   maps to the following syntax in OMG IDL.

   // OMG IDL const long N = ...; typedef string<N> BOUNDED_STRING;

   In other words, the encoding for a value of type BOUNDED_STRING is that of a null-terminated array of characters whose extent is known at compile time, and whose number of valid characters can vary at run-time.

   18.3.4.3 Mapping for Unicode Unbounded String Types

   The mapping for a Unicode unbounded string type in Microsoft IDL or ODL is no different from that used for ANSI string types. The following Microsoft IDL and ODL statement

   // Microsoft IDL and ODL typedef [string, unique] LPWSTR UNBOUNDED_UNICODE_STRING;

   is mapped to the following syntax in OMG IDL.

   // OMG IDL typedef wstring UNBOUNDED_UNICODE_STRING;

   It is the responsibility of the mapping implementation to perform the conversions between ANSI and Unicode formats when dealing with strings.

   18.3.4.4 Mapping for unicode bound string types

   The mapping for a Unicode bounded string type in Microsoft IDL or ODL is no different from that used for ANSI string types. The following Microsoft IDL and ODL statements

   // Microsoft IDL and ODL const long N = ...; typedef [string, unique] wchar t(*

   BOUNDED_UNICODE_STRING) [N];

   map to the following syntax in OMG IDL.

   // OMG IDL const long N = ...; typedef wstring<N> BOUNDED_UNICODE_STRING;

   It is the responsibility of the mapping implementation to perform the conversions between ANSI and Unicode formats when dealing with strings.