Coding knowledge
A, Unicode multibyte
(. 1) the Windows in , also called Unicode wide multibyte also called narrow byte; VS default use Unicode encoding , in the configuration attribute item attributes >> >> conventional character sets selectable Unicode characters multi-byte character set or sets
(2) Unicode version of the function and multi-byte character string type distinction
Most parameters have a string of the Win32 API functions have two versions
Ending with A, on behalf of multi-byte version | Ending in W, on behalf of the Unicode version | Depending on the version automatically selected |
---|---|---|
Such as: CreateEventA | Such as: CreateEventW | Such as: CreateEvent |
C runtime library also has many similar functions
Multi-byte version | Unicode version | Adaptive version |
---|---|---|
strcpy | wcscpy | _tcscpy |
strcat | wcscat | _tscscat |
strlen | wcslen | _tcslen |
There are two functions, so there are two characters
Multi-byte characters | Unicode character | Adaptive character |
---|---|---|
char | wchar_t | TCHAR |
(3) common Win32 string type
LPSTR、LPWSTR、LPTSTR、LPCTSTR
LP prefix representative pointer; suffix string representing the STR
LPSTR: on behalf of multi-byte
LPWSTR: on behalf of Unicode
LPTSTR: T adaptive
LPCTSTR: C Representative Representative adaptive const + T
NOTE: Use the variable type, such as an adaptive type LPTSTR, associated strings need to use the TEXT () wrapped
const char* str = "hello";
const wchar_t* wstr = L"hello";
const TCHAR* tstr = TEXT("hello");
(4) on _T ()
#ifdef _UNICODE
#define _T(X) L ## X //Unicode版本
#endif
#ifndef _UNICODE
#define _T(X) X //多字节版本
#endif
(5) Unicode multibyte selection
1.Unicode program environmental adaptability, will not be garbled problem
2.Unicode program runs faster than the multi-byte program. Cause: An internal Windows are encoded using Unicode, multi-byte function parameters will be handed over to Unicode function after transcoding
3. Background may be multi-byte control, GUI program is preferable to use Unicode