.......... // // Basics // #ifndef VOID #define VOID void typedef char CHAR; typedef short SHORT; typedef long LONG; #if !defined (MIDL_PASS) typedef int INT; #endif #endif // // UNICODE (Wide Character) types // #ifndef _MAC typedef wchar_t WCHAR; // wc, 16-bit UNICODE character #else // some Macintosh compilers don't define wchar_t in a convenient location, or define it as a char typedef unsigned short WCHAR; // wc, 16-bit UNICODE character #endif typedef WCHAR *PWCHAR, *LPWCH, *PWCH; typedef CONST WCHAR *LPCWCH, *PCWCH; typedef __nullterminated WCHAR *NWPSTR, *LPWSTR, *PWSTR; typedef __nullterminated PWSTR *PZPWSTR; typedef __nullterminated CONST PWSTR *PCZPWSTR; typedef __nullterminated WCHAR UNALIGNED *LPUWSTR, *PUWSTR; typedef __nullterminated CONST WCHAR *LPCWSTR, *PCWSTR; typedef __nullterminated PCWSTR *PZPCWSTR; typedef __nullterminated CONST WCHAR UNALIGNED *LPCUWSTR, *PCUWSTR; typedef __nullnullterminated WCHAR *PZZWSTR; typedef __nullnullterminated CONST WCHAR *PCZZWSTR; typedef __nullnullterminated WCHAR UNALIGNED *PUZZWSTR; typedef __nullnullterminated CONST WCHAR UNALIGNED *PCUZZWSTR; typedef __possibly_notnullterminated WCHAR *PNZWCH; typedef __possibly_notnullterminated CONST WCHAR *PCNZWCH; typedef __possibly_notnullterminated WCHAR UNALIGNED *PUNZWCH; typedef __possibly_notnullterminated CONST WCHAR UNALIGNED *PCUNZWCH; #if _WIN32_WINNT >= 0x0600 || (defined (__cplusplus) && defined(WINDOWS_ENABLE_CPLUSPLUS)) typedef CONST WCHAR *LPCWCHAR, *PCWCHAR; typedef CONST WCHAR UNALIGNED *LPCUWCHAR, *PCUWCHAR; // // UCS (Universal Character Set) types // typedef unsigned long UCSCHAR; // // Even pre-Unicode agreement, UCS values are always in the // range U+00000000 to U+7FFFFFFF, so we'll pick an obvious // value. #define UCSCHAR_INVALID_CHARACTER (0xffffffff) #define MIN_UCSCHAR (0) // // We'll assume here that the ISO-10646 / Unicode agreement // not to assign code points after U+0010FFFF holds so that // we do not have to have separate "UCSCHAR" and "UNICODECHAR" // types. // #define MAX_UCSCHAR (0x0010FFFF) typedef UCSCHAR *PUCSCHAR; typedef const UCSCHAR *PCUCSCHAR; typedef UCSCHAR *PUCSSTR; typedef UCSCHAR UNALIGNED *PUUCSSTR; typedef const UCSCHAR *PCUCSSTR; typedef const UCSCHAR UNALIGNED *PCUUCSSTR; typedef UCSCHAR UNALIGNED *PUUCSCHAR; typedef const UCSCHAR UNALIGNED *PCUUCSCHAR; #endif // _WIN32_WINNT >= 0x0600 // // ANSI (Multi-byte Character) types // typedef CHAR *PCHAR, *LPCH, *PCH; typedef CONST CHAR *LPCCH, *PCCH; typedef __nullterminated CHAR *NPSTR, *LPSTR, *PSTR; typedef __nullterminated PSTR *PZPSTR; typedef __nullterminated CONST PSTR *PCZPSTR; typedef __nullterminated CONST CHAR *LPCSTR, *PCSTR; typedef __nullterminated PCSTR *PZPCSTR; typedef __nullnullterminated CHAR *PZZSTR; typedef __nullnullterminated CONST CHAR *PCZZSTR; typedef __possibly_notnullterminated CHAR *PNZCH; typedef __possibly_notnullterminated CONST CHAR *PCNZCH; // // Neutral ANSI/UNICODE types and macros // #ifdef UNICODE // r_winnt #ifndef _TCHAR_DEFINED typedef WCHAR TCHAR, *PTCHAR; typedef WCHAR TBYTE , *PTBYTE ; #define _TCHAR_DEFINED #endif /* !_TCHAR_DEFINED */ typedef LPWCH LPTCH, PTCH; typedef LPCWCH LPCTCH, PCTCH; typedef LPWSTR PTSTR, LPTSTR; typedef LPCWSTR PCTSTR, LPCTSTR; typedef LPUWSTR PUTSTR, LPUTSTR; typedef LPCUWSTR PCUTSTR, LPCUTSTR; typedef LPWSTR LP; typedef PZZWSTR PZZTSTR; typedef PCZZWSTR PCZZTSTR; typedef PUZZWSTR PUZZTSTR; typedef PCUZZWSTR PCUZZTSTR; typedef PNZWCH PNZTCH; typedef PCNZWCH PCNZTCH; typedef PUNZWCH PUNZTCH; typedef PCUNZWCH PCUNZTCH; #define __TEXT(quote) L##quote // r_winnt #else /* UNICODE */ // r_winnt #ifndef _TCHAR_DEFINED typedef char TCHAR, *PTCHAR; typedef unsigned char TBYTE , *PTBYTE ; #define _TCHAR_DEFINED #endif /* !_TCHAR_DEFINED */ typedef LPCH LPTCH, PTCH; typedef LPCCH LPCTCH, PCTCH; typedef LPSTR PTSTR, LPTSTR, PUTSTR, LPUTSTR; typedef LPCSTR PCTSTR, LPCTSTR, PCUTSTR, LPCUTSTR; typedef PZZSTR PZZTSTR, PUZZTSTR; typedef PCZZSTR PCZZTSTR, PCUZZTSTR; typedef PNZCH PNZTCH, PUNZTCH; typedef PCNZCH PCNZTCH, PCUNZTCH; #define __TEXT(quote) quote // r_winnt #endif /* UNICODE */ // r_winnt .......... |
LP = Long Pointer W = Wide C = Const T = Template STR = Null Terminated |
char = 1바이트 문자 wchar_t = WCHAR = 2바이트 문자
char* = LPSTR = 1바이트 문자열 |
KSC5601 : 한글 완성형 표준(한글 2,350자표현), 한국공업표준 정보처리분야( C )의 5601번 표준안 KSC5636 : ASCII 코드를 확장하여 한글을 표현하므로 ASCII와 호환되며 역슬래시 대신 원화기호를 사용한다는 점이 ASCII와 다르다 EUC-KR : Bell 연구소에서 제안한 한글표현 방식, 영문은 KSC5636, 한글은 KSC5601으로 처리. 완성형 코드라서 조합형 코드에 비해 문자표현 수에 한계가 있다 MS949(CP949) : 마이크로소프트의 윈도우 95에서 사용하기 시작한 한글 표현방식, 조합형은 아니지만 EUC-KR형식을 확장하여 더 많은 한글을 표현함 |
SBCS (Single-Byte Character Set) : 1바이트로 영문자 한개를 표현, ASCII코드체계는 SBCS에 속한다 DBCS (Double-Byte Character Set) : 한개의 문자를 2바이트로 표현, SBCS와 호환이 안되어 MBCS가 고안됨. 각국에서 비표준적으로 사용됨 MBCS (Multi-Byte Character Set) : 한개의 문자는 1~2바이트로 표현됨, 서로다른 언어 안에 동일한 코드를 가질 수 있는 문제가 있으므로 각 언어셋을 설정해야 하는 단점이 있다, ANSI, UTF-8, UTF-16 등은 MBCS에 속한다 WBCS : 국제표준문자집합으로 유니코드를 지원하기 위한 방식. 각국 언어가 한 테이블에 정의되므로 각 언어를 표현하는 언어셋이 필요없다. VC++ 에서는MBCS와 Unicode가 사용되며 2바이트를 넘는 문자는 지원되지 않는다 |
UTF-8 : 영문자는 1 바이트(8비트)로, 그 외의 문자는 2~4 바이트로 표현함 UTF-16 : 모든 문자를 2~4바이트로 표현함, Windows NT 운영체제부터 적용되고 있는 방식 UTF-32 : UCS-4와 동일하나 17개 언어만 정의한다는 점에서 UCS-4의 부분집합이라고 할 수 있다 UCS-2(Universal Character Set 2(octets)) : 한 문자를 2바이트로 고정하여 표현함, 일반적으로 유니코드라고 불림 UCS-4 (Universal Character Set 4(octets)) : 한 문자를 4바이트로 고정하여 표현함, 인코딩 방법일 뿐만 아니라 문자코딩 자체임 |
SBCS 기반 함수 | WBCS 기반 함수 |
size_t strlen (const char *s) | size_t wcslen (const wchar_t *ws) |
size_t strnlen (const char *s, size_t maxlen) | size_t wcsnlen (const wchar_t *ws, size_tmaxlen) |
void * memcpy (void *restrict to, const void *restrict from, size_t size) | wchar_t * wmemcpy (wchar_t *restrict wto, const wchar_t *restruct wfrom, size_t size) |
void * mempcpy (void *restrict to, const void *restrict from, size_t size) | wchar_t * wmempcpy (wchar_t *restrict wto, const wchar_t *restrict wfrom, size_t size) |
void * memmove (void *to, const void *from, size_t size) | wchar_t * wmemmove (wchar *wto, const wchar_t *wfrom, size_t size) |
void * memset (void *block, int c, size_t size) | wchar_t * wmemset (wchar_t *block, wchar_twc, size_t size) |
char * strcpy (char *restrict to, const char *restrict from) | wchar_t * wcscpy (wchar_t *restrict wto, const wchar_t *restrict wfrom) |
char * strncpy (char *restrict to, const char *restrict from, size_t size) | wchar_t * wcsncpy (wchar_t *restrict wto, const wchar_t *restrict wfrom, size_t size) |
char * strdup (const char *s) | wchar_t * wcsdup (const wchar_t *ws) |
char * stpcpy (char *restrict to, const char *restrict from) | wchar_t * wcpcpy (wchar_t *restrict wto, const wchar_t *restrict wfrom) |
char * stpncpy (char *restrict to, const char *restrict from, size_t size) | wchar_t * wcpncpy (wchar_t *restrict wto, const wchar_t *restrict wfrom, size_t size) |
char * strcat (char *restrict to, const char *restrict from) | wchar_t * wcscat (wchar_t *restrict wto, const wchar_t *restrict wfrom) |
char * strncat (char *restrict to, const char *restrict from, size_t size) | wchar_t * wcsncat (wchar_t *restrict wto, const wchar_t *restrict wfrom, size_t size) |
int memcmp (const void *a1, const void *a2, size_t size) | int wmemcmp (const wchar_t *a1, const wchar_t *a2, size_t size) |
int strcmp (const char *s1, const char *s2) | int wcscmp (const wchar_t *ws1, const wchar_t *ws2) |
int strcasecmp (const char *s1, const char *s2) | int wcscasecmp (const wchar_t *ws1, const wchar_T *ws2) |
int strncmp (const char *s1, const char *s2, size_t size) | int wcsncmp (const wchar_t *ws1, const wchar_t *ws2, size_t size) |
int strncasecmp (const char *s1, const char *s2, size_t n)(GNU only) | int wcsncasecmp (const wchar_t *ws1, const wchar_t *s2, size_t n) (GNU only) |
int strcoll (const char *s1, const char *s2) | int wcscoll (const wchar_t *ws1, const wchar_t *ws2) |
size_t strxfrm (char *restrict to, const char *restrict from, size_t size) | size_t wcsxfrm (wchar_t *restrict wto, const wchar_t *wfrom, size_t size) |
void * memchr (const void *block, int c, size_tsize) | wchar_t * wmemchr (const wchar_t *block, wchar_t wc, size_t size) |
char * strchr (const char *string, int c) | wchar_t * wcschr (const wchar_t *wstring, intwc) |
char * strchrnul (const char *string, int c) | wchar_t * wcschrnul (const wchar_t *wstring, wchar_t wc) |
char * strrchr (const char *string, int c) | wchar_t * wcsrchr (const wchar_t *wstring, wchar_t c) |
char * strstr (const char *haystack, const char *needle) | wchar_t * wcsstr (const wchar_t *haystack, const wchar_t *needle) wchar_t * wcswcs (const wchar_t *haystack, const wchar_t *needle) |
size_t strspn (const char *string, const char *skipset) | size_t wcsspn (const wchar_t *wstring, const wchar_t *skipset) |
size_t strcspn (const char *string, const char *stopset) | size_t wcscspn (const wchar_t *wstring, const wchar_t *stopset) |
char * strpbrk (const char *string, const char *stopset) | wchar_t * wcspbrk (const wchar_t *wstring, const wchar_t *stopset) |
char * strtok (char *restrict newstring, const char *restrict delimiters) | wchar_t * wcstok (wchar_t *newstring, const char *delimiters) |
TCHAR/_TCHAR : 마이크로소프트사에서 만든 문자열 타입. 동일한 기능 VC 에서는 컴파일 시에 지정된 옵션에 따라서 MBCS, Unicode 형식이 적용됨, 즉, 설정옵션에 따라서 wchar_t 혹은 char 형으로 변환되어 컴파일 됨 TCHAR : winnt.h에 선언되어 있으므로 <windows.h>를 포함하는 코드에서 사용할 수 있다. VC를 사용하는 대부분의 환경에서 사용가능 _TCHAR : tchar.h에 선언되어 있다. VC가 아닌 컴파일러에서 윈도우 프로그래밍을 할 때 사용 TCHAR는 Windows SDK에 포함되어 있고 _TCHAR은 CRT에 포함되어 있다 TCHAR 자료형을 사용하면 MBCS, Unicode 방식을 가리지 않고 동일한 방법으로 코드를 작성할 수 있는 장점을 가지게 된다 마이크로소프트에서는 TCHAR 자료형을 사용하더라도 ANSI 표준 자료형으로 정해진 것은 아니다. 그러므로 VC가 아닌 다른 환경에서는 개발자가 변수이름으로 TCHAR 이라는 변수를 선언하는 실수를 범할 가능성도 있으므로 좀더 입력이 까다로운 _TCHAR 이라는 키워드를 사용하게 된것이다. ANSI 규정에 따라 특정 컴파일러에 특화된 자료형 앞에는 '_' 문자를 붙이게 된 것이다 |
typedef char CHAR ; typedef wchar_t WCHAR ; #define CONST const typedef CHAR * LPSTR ; typedef CONST CHAR * LPCSTR ; typedef CONST WCHAR * LPCWSTR ; typedef WCHAR * LPWSTR ; #ifdef UNICODE typedef WCHAR TCHAR ; typedef LPWSTR LPTSTR ; typedef LPCWSTR LPCTSTR ; #else typedef CHAR TCHAR ; typedef LPSTR LPTSTR ; typedef LPCSTR LPCTSTR ; #endif #ifdef _UNICODE #define __T(x) L ## x #define _tmain wmain #define _tcslen wcslen #define _tcscat wcscat #define _tcscpy wcscpy #define _tcsncpy wcsncpy #define _tcscmp wcscmp #define _tcsncmp wcsncmp #define _tprintf wprintf #define _tscanf wscanf #define _fgetts fgetws #define _fputts fputws #else #define __T(x) x #define _tmain main #define _tcslen strlen #define _tcscat strcat #define _tcscpy strcpy #define _tcsncpy strncpy #define _tcscmp strcmp #define _tcsncmp strncmp #define _tprintf printf #define _tscanf scanf #define _fgetts fgets #define _fputts fputs #endif #define _T(x) __T(x) #define _TEXT(x) __T(x) [출처] Win32 API 유니코드|작성자 씨피유 |
1. Formatted I/O | ||
MACRO | ANSI | UNICODE |
_tprintf | printf | wprintf |
_ftprintf | fprintf | fwprintf |
_stprintf | sprint | swprintf |
_sntprintf | _snprintf | _snwprintf |
_vtprintf | vprintf | vwprintf |
_vftprintf | vfprintf | vfwprintf |
_vstprintf | vsprintf | vswprintf |
_vsntprintf | _vsnprintf | _vsnwprintf |
_tscanf | scanf | wscanf |
_ftscanf | fscanf | fwscanf |
_stscanf | sscanf | swscanf |
2. Formatted I/O | ||
MACRO | ANSI | UNICODE |
_fgettc | fgetc | fgetwc |
_fgetts | fgets | fgetwc |
_fputtc | fputc | fputwc |
_fputts | fputs | fputws |
_gettc | getc | getwc |
_gettchar | getchar | getwchar |
_getts | gets | _getws |
_puttc | putc | putwc |
_puttchar | putchar | putwchar |
_putts | puts | _putws |
_ungettc | ungetc | ungetwc |
3. Stdio function | ||
MACRO | ANSI | UNICODE |
_tfopen | _wfopen | |
_tfreopen | _wfreopen | |
4. String conversion function | ||
MACRO | ANSI | UNICODE |
_tcstod | strtod | wcstod |
_tcstol | strtol | wcstol |
_tcstoul | strtoul | wcstoul |
_itot | _itoa | _itow |
_ltot | _ltoa | _ltow |
_ultot | _ultoa | _ultow |
_ttoi | atoi | _wtoi |
_ttol | atol | _wtol |
5. String function | ||
MACRO | ANSI | UNICODE |
_tcscat | strcat | wcscat |
_tcschr | strchr | wcschr |
_tcscmp | strcmp | wcscmp |
_tcscpy | strcpy | wcscpy |
_tcscspn | strcspn | wcscspn |
_tcslen | strlen | wcslen |
_tcsclen | strlen | wcslen |
_tcsncat | strncat | wcsncat |
_tcsnccat | strncat | wcsncat |
_tcsnccmp | strncmp | wcsncmp |
_tcsncmp | strncmp | wcsncmp |
_tcsncpy | strncpy | wcsncpy |
_tcsnccpy | strncpy | wcsncpy |
_tcspbrk | strpbrk | wcspbrk |
_tcsrchr | strrchr | wcsrchr |
_tcsspn | strspn | wcsspn |
_tcsstr | strstr | wcsstr |
_tcstok | strtok | wcstok |
_tcsdup | _strdup | _wcsdup |
_tcsicmp | _stricmp | _wcsicmp |
_tcsncicmp | _strnicmp | _wcsnicmp |
_tcsnicmp | _strnicmp | _wcsnicmp |
_tcsnset | _strnset | _wcsnset |
_tcsncset | _strnset | _wcsnset |
_tcsrev | _strrev | _wcsrev |
_tcsset | _strset | _wcsset |
_tcslwr | _strlwr | _wcslwr |
_tcsupr | _strupr | _wcsupr |
6. ctype function | ||
MACRO | ANSI | UNICODE |
_istalpha | isalpha | iswalpha |
_istupper | isupper | iswupper |
_istlower | islower | iswlower |
_istdigit | isdigit | iswdigit |
_istxdigit | isxdigit | iswxdigit |
_istspace | isspace | iswspace |
_istpunct | ispunct | iswpunct |
_istalnum | isalnum | iswalnum |
_istprint | isprint | iswprint |
_istgraph | isgraph | iswgraph |
_istcntrl | iscntrl | iswcntrl |
_istascii | isascii | iswascii |
_totupper | toupper | towupper |
_totlower | tolower | towlower |