Simplify the function of string ANSI and Unicode in WinCE

xiaoxiao2021-03-06  39

// convert from a string to a unicode number of bytes size_t GetT2AStringByteCount (LPCTSTR lpszInput) dbcs string needs; // how many bytes size_t GetA2TStringByteCount convert from a string to a unicode string need dbcs (LPCSTR lpszInput); // convert the unicode string dbcs string to void T2AString (LPCTSTR lpszInput, LPSTR lpszOutput); // convert dbcs string to unicode string void A2TString (LPCSTR lpszInput, LPTSTR lpszOutput); size_t GetT2AStringByteCount (LPCTSTR lpszInput) {return WideCharToMultiByte (// calculated from Unicode The number of bytes required after ANSI CP_ACP, // According to ANSI Code Page | WC_COMPOSITECHECK | WC_SEPCHARS / * WC_DEFAULTCHAR * /, / / ​​Converted Dismun, default characters instead of lpszinput, // To convert string address - 1 / * NTCHARNUM * / Character: "/ 0" 0 // Default settings);} size_t geta2tstringBytecount (LPCSTR LPSZINPUT) {RETURN 2 * MULTIBYTOWIDECHAR (// Calculate the number of bytes required from ANSI to Unicode) CP_ACP, MB_PREComposed / * MB_Composite * /, LPSZINPUT, // To convert the ANSI string -1, // automatic calculation length 0, 0);} void t2astring (lpctstr lpszinput, lpstr lpszoutput) {int ncharnum = Get T2AStringByteCount (lpszInput); WideCharToMultiByte (CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, lpszInput, -1 / * nTCHARNum * /, lpszOutput, nCharNum, 0, 0);} void A2TString (LPCSTR lpszInput, LPTSTR lpszOutput) {int nTCHARNum = GetA2TStringByteCount (lpszInput) ; MultiByteToWideChar (CP_ACP, MB_COMPOSITE, lpszInput, -1, lpszOutput, nTCHARNum / 2);} using the exemplary void CStrtestDlg :: OnButton1 () {// TODO: Add your control notification handler code here LPTSTR lpszInput = _T ( "hello hello "); Int ncount = gett2AStringBytecount (LPSZINPUT); Trace ("% D / N "), ncount); lpstr lpszoutput = new char [ncount 1]; Memset (lpszoutput, 0, ncount 1); t2astring LPSZINPUT, LPSZOUTPUT; for (int i = 0; i <= ncount;

i) Trace (_T ("% c"), * (lpszoutput i)); trace (_t ("/ n")); delete [] lpszoutput;}

void CStrtestDlg :: OnButton2 () {// TODO: Add your control notification handler code here LPSTR lpszInput = "hello hello"; int nCount = GetA2TStringByteCount (lpszInput); TRACE (_T ( "% d / n"), nCount) LPTSTR LPSZOUTPUT = New Tchar [ncount / 2]; MEMSET (LPSZoutput, 0, Ncount); A2TSTRING (LPSZINPUT, LPSZOUTPUT); Trace ("% s / n"), lpszoutput; delete [] lpszoutput;

转载请注明原文地址:https://www.9cbs.com/read-72329.html

New Post(0)