A Warning Regarding Temporary Class Instances
It should be stressed that the following is not good code:
Using ATL 3.0 macros, it was acceptable to use:
as the memory allocated by the conversion functions would not be freed until the current function was exited. The same code does not work with the new classes.
is equivalent to this:
As the memory allocated by the temporary object and returned from the cast operator is destroyed when the temporary object is destroyed, using the value in szr will have undesirable results.
Instead, use this code:
The cast operator makes the CA2T object look like a LPCTSTR.
The default static buffer size is 128 characters. If the buffer size must be changed for a specific conversion, use the EX version of a macro, and specify the buffer size as a template argument.
Here is an example of specifying the code page as the second parameter to the constructor for the class.