Should I use CString, basic_string <TCHAR> or something else with ATL / WTL?

I learned a little ATL in the last couple of days (after I realized how clean Win32 is), and also learned about WTL and MFC, and from what I see, there are quite a few different line classes available to me.

I was doing something like this:

#include <tchar.h> #include <string> namespace std { typedef basic_string<TCHAR> _tstring; } 

and then use _tstring everywhere in my code. After learning some ATL, I found out that there is a CString class in atltmp.h . There appears to be another CString class in WTL and another CString class in MFC.

I do n’t know if I will stick to ATL or switch to WTL, MFC or something else. But right now, I'm in the process of converting my Win32 code to ATL, and I'm not sure what to change and what to save.

Should I use CString strings instead of _tstring ? Is there any benefit in this, considering both the executable size (excluding shared libraries) and portability / compatibility?

+4
source share
2 answers

Something I just read is that CString does not support null characters.

I think I will continue to use STL.

0
source

My preference would be to stick with CString for ATL / MFC / WTL. It doesn't seem like you have many portability opportunities if you use these frameworks anyway; and you know what they say: When in Rome ...

In addition, CString has a few subtleties about this.

  • You can load resource strings from executables using CString::LoadString
  • Get direct access to an internal string buffer using CString::GetBuffer/ReleaseBuffer
  • CStringA convert between CStringA and CStringW
  • Perform printf formatting with CString::Format
+6
source

Source: https://habr.com/ru/post/1369215/


All Articles