Talk about ATL (i)--Talk about the ATL string conversion class

Source: Internet
Author: User
Tags ole

When you use ATL technology to do projects, must have found a very troublesome string character set problem, the following list of common points and key records for future reference.

ATL provides a number of string conversion functions, and if the compilation option makes the source and destination character types the same, then these classes do not perform any conversions, as described in the article on setting up system compilation items before Windows programming. If you want to use the character conversion class of ATL, then you must include the <atlconv.h> file, the specific way of conversion is done by macro definition (macro function), in order to better list these macro functions and clarify their functions, you need to explain what the string types and their abbreviations:

T represents a pointer to the TCHAR character of Win32----a LPTSTR parameter.

W represents a pointer to the Unicode wchar_t character----a lpwstr parameter.

A represents a pointer to a char character of mbcs/ansi----a LPSTR parameter.

OLE represents a pointer to a COM olechar character----a lpolestr parameter.

C represents the const modifier for C/D + +.

The names of all macro functions are in the form of a uniform < source format abbreviation >2< target abbreviation >, where "2" takes its English pronunciation "to", that is, from source to destination. For example, a2w is to convert LPSTR to LPWSTR, if the name contains C, it represents the const, for example, T2CW is to LPTStr to LPCWSTR. The list of character conversion macros for ATL is listed below

a2w ole2t T2CA t2w w2t

A2wex Ole2tex T2caex T2wex W2tex

A2T ole2ct t2ole T2CW w2ct

A2tex Ole2ctex T2oleex T2cwex W2ctex

A2CT T2A t2cole W2A

A2ctex T2aex T2coleex W2aex

The character set that requires special instructions is Olechar, in the case of Unicode, Ole equals W, for example: COLE2T and cw2t are equivalent.

This is inseparable from the definition of Olechar, on Win16 's Windows operating system, OLECHAR is defined by a typedef with the standard C data type Char containing ANSI characters, and on the Win32 system, the Wchar_ T data types are defined with typedef. Because of the adaptive olechar, it is common to define all COM interface string parameters as olechar* types.


This article is from the "8403723" blog, please be sure to keep this source http://8413723.blog.51cto.com/8403723/1729777

Talk about ATL (i)--Talk about the ATL string conversion class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.