classctools{ Public: Ctools (void); Public: ~ctools (void); Public: StaticSTD::stringUnicode_to_utf8 (Constcstring&unicodestring); StaticCString Utf8_to_unicode (ConstSTD::string&utf8_string); StaticSTD::stringWs2s (std::wstring&Inputws); StaticStd::wstring S2ws (ConstSTD::string&s); StaticSTD::stringUnicode_to_ansi (Constcstring&unicodestring); StaticCString Ansi_to_unicode (ConstSTD::string&utf8_string); StaticSTD::stringGetFullPath (void);}; Ctools::ctools (void) {}ctools::~ctools (void) {}std::stringCtools::unicode_to_utf8 (Constcstring&unicodestring) { intStringlength =:: WideCharToMultiByte (Cp_utf8, NULL, UnicodeString, (int) Wcslen (unicodestring), NULL,0, NULL, NULL); Char* Buffer =New Char[Stringlength +1]; :: WideCharToMultiByte (Cp_utf8, NULL, UnicodeString, (int) Wcslen (unicodestring), buffer, stringlength, NULL, NULL); Buffer[stringlength]=' /'; STD::stringstr =buffer; Delete[] buffer; returnstr;} CString Ctools::utf8_to_unicode (ConstSTD::string&utf8_string) { intLength = (int) utf8_string.size (); intWcsLen =:: MultiByteToWideChar (Cp_utf8, NULL, UTF8_STRING.C_STR (), Length, NULL,0); wchar_t* Wszstring =NewWchar_t[wcslen +1]; :: MultiByteToWideChar (Cp_utf8, NULL, Utf8_string.c_str (), length, wszstring, WcsLen); Wszstring[wcslen]=' /'; CString UnicodeText (wszstring); Delete[] wszstring; returnUnicodeText;} STD::stringCtools::unicode_to_ansi (Constcstring&unicodestring) { intStringlength =:: WideCharToMultiByte (CP_ACP, NULL, UnicodeString, (int) Wcslen (unicodestring), NULL,0, NULL, NULL); Char* Buffer =New Char[Stringlength +1]; :: WideCharToMultiByte (CP_ACP, NULL, UnicodeString, (int) Wcslen (unicodestring), buffer, stringlength, NULL, NULL); Buffer[stringlength]=' /'; STD::stringstr =buffer; Delete[] buffer; returnstr;} CString Ctools::ansi_to_unicode (ConstSTD::string&utf8_string) { intLength = (int) utf8_string.size (); intWcsLen =:: MultiByteToWideChar (CP_ACP, NULL, UTF8_STRING.C_STR (), Length, NULL,0); wchar_t* Wszstring =NewWchar_t[wcslen +1]; :: MultiByteToWideChar (CP_ACP, NULL, Utf8_string.c_str (), length, wszstring, WcsLen); Wszstring[wcslen]=' /'; CString UnicodeText (wszstring); Delete[] wszstring; returnUnicodeText;} STD::stringCtools::ws2s (std::wstring&Inputws) { returnUnicode_to_utf8 (Inputws.c_str ());} Std::wstring Ctools::s2ws (ConstSTD::string&s) {CString CStr=Utf8_to_unicode (s); returnCStr. GetBuffer (CStr. GetLength ());} STD::stringCtools::getfullpath (void) {hmodule h= GetModuleHandle (L"Test.exe"); wchar_t Exefullpath[max_path]; //MAX_PATH is defined in the API and is intlen=GetModuleFileName (H, Exefullpath,//full path storage address for the applicationMAX_PATH); Std::wstring Wstrpath=Exefullpath; STD::stringstrpath =ctools::ws2s (Wstrpath); size_t NPos; NPos=strpath.rfind ('\\'); returnSTRPATH.SUBSTR (0, NPos); }
Tool class Ctools implement character encoding conversion and get current path