Unicode <-> ASCII A2U U2A W2A T2A A2W A2T Posted by 빵빵빵 2009/07/01 22:34 전산(컴퓨터)/Mobile-CE&PPC 전산(컴퓨터)/Mobile-CE&PPC 메크로를 사용하는 방법 USES_CONVERSION; // Unicode 를 Ascii 로 변환 하고자 할 경우W2A(LPWSTR), T2A(LPWSTR) // Ascii 를 Unicode로 변경하고자 하는경우A2W(LPSTR), A2T(LPSTR) // MSDN 의 예제 //Example 1 // Convert LPCWSTR to LPCSTR. void ExampleFunctionW( LPCWSTR pszW ) { // Create an instance of CW2A, called pszA, // and initialize it with pszW. CW2A pszA( pszW ); // pszA works like an LPCSTR, and can be used thus: ExampleFunctionA( pszA ); // Note: pszA will become invalid when it goes out of scope. } // Example 2 // Use a temporary instance of CW2A. void ExampleFunctionW( LPCWSTR pszW ) { // Create a temporary instance of CW2A, // and initialize it with pszW. ExampleFunctionA( CW2A( pszW ) ); // Note: the temporary instance becomes invalid // after the execution of the statement above. } // Example 3 // Incorrect use of conversion macros. void ExampleFunctionW( LPCWSTR pszW ) { // Create a temporary instance of CW2A, // save a pointer to it and then delete // the temportary instance. LPCSTR pszA = CW2A( pszW ); // The pszA in the following line is an invalid pointer, // as the instance of CW2A has gone out of scope. ExampleFunctionA( pszA ); } API를 사용하는 방법 // Ascii 를 Unicode 로 변환할 경우 int MultiByteToWideChar( UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, int cbMultiByte, LPWSTR lpWideCharStr, int cchWideChar ); // Unicode를 Ascii 로 변환할 경우 int WideCharToMultiByte( UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte, LPCSTR lpDefaultChar, LPBOOL lpUsedDefaultChar ); 사용방법 // Ascii 를 Unicode 로 변환할 경우 char szSource[1024] = "Sample Ascii string"; WCHAR wszBuf[1024]; int nBufSize = 1024; MultiByteToWideChar( CP_ACP, 0, szSource, -1, wszBuf, nBufSize); // Unicode를 Ascii 로 변환할 경우 WCHAR wszSource[1024] = _T("Sample Unicode string"); char szDest[1024]; int nBufSize = 1024; WideCharToMultiByte( CP_ACP, 0, wszSource, -1, szDest, nBufSize, NULL, NULL ); 2009/07/01 22:34 2009/07/01 22:34 Tags A2T, A2U, A2W, ASCII, CONVERT, T2A, U2A, Unicode, W2A, 유니코드 Trackback: 0 Comment: 0 이 글에는 트랙백을 보낼 수 없습니다