Legacy/뇌자극 - WinSysProg
2014.12.21 LPCTSTR LPTSTR
Foo
2014. 12. 21. 10:36

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | LPSTR CHAR * LPCSTR CONST CHAR * LPWSTR WCHAR * LPCWSTR CONST WCHAR * #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 #else #define __T(x) x #endif #define _T(x) __T(x) #define _TEXT(x) __T(x) #ifdef _UNIDOCE #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 _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
| cs |
tchar.h는 windows.h에 포함되지 않음.
최종 예제
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #define UNICODE #define _UNICODE #include <stdio.h> #include <tchar.h> #include <Windows.h> int _tmain(int argc, TCHAR* argv[]) { LPTSTR str1 = _T("MBCS or WBCS 1"); TCHAR str2[] = _T("mbcs OR wbcd 2"); TCHAR str3[100]; TCHAR str4[50]; LPCTSTR pStr = str1; _tprintf( _T("string size: %d \n"), sizeof(str2) ); _tprintf( _T("string length: %d \n"), _tcslen(pStr) ); _fputts(_T("Input String 1 : "), stdout); _tscanf(_T("%s"), str3); _fputts(_T("Input String 2 : "), stdout); _tscanf(_T("%s"), str4); _tcscat(str3, str4); _tprintf( _T("String1 + String2 : %s \n"), str3); return 0; }
| cs |