读书人

SDK网络连接/多线程示范代码

发布时间: 2012-07-31 12:33:46 作者: rapoo

SDK网络连接/多线程示例代码

SDK网络连接/多线程示例代码
2010年06月09日
  

   using namespace std;   class MzConvert   {   public:   static wstring string2wstring(const string& s)   {   int len;   int slength = (int)s.length() + 1;   len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);   wchar_t* buf = new wchar_t[len];   MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);   std::wstring r(buf);   delete[] buf;   return r;   }   static wstring ANSIToUnicode( const string& str )   {   int len = str.length();   int unicodeLen = ::MultiByteToWideChar( CP_ACP, 0, str.c_str(), -1, NULL, 0 );   wchar_t * pUnicode;   pUnicode = new wchar_t[unicodeLen+1];   memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));   MultiByteToWideChar( CP_ACP, 0, str.c_str(), -1, (LPWSTR)pUnicode, unicodeLen );   wstring rt = ( wchar_t* )pUnicode;   delete pUnicode;   return rt;   }   static string UnicodeToANSI( const wstring& str )   {   char* pElementText;   int iTextLen;   // wide char to multi char   iTextLen = WideCharToMultiByte( CP_ACP, 0, str.c_str(), -1, NULL, 0, NULL, NULL );   pElementText = new char[iTextLen + 1];   memset( ( void* )pElementText, 0, sizeof( char ) * ( iTextLen + 1 ) );   WideCharToMultiByte( CP_ACP, 0, str.c_str(), -1, pElementText, iTextLen, NULL, NULL );   string strText = pElementText;   delete[] pElementText;   return strText;   }   static wstring UTF8ToUnicode( const string& str )   {   int len = str.length();   int unicodeLen = ::MultiByteToWideChar( CP_UTF8, 0, str.c_str(), -1, NULL, 0 );   wchar_t * pUnicode;   pUnicode = new wchar_t[unicodeLen+1];   memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));   MultiByteToWideChar( CP_UTF8, 0, str.c_str(), -1, (LPWSTR)pUnicode, unicodeLen );   wstring rt = ( wchar_t* )pUnicode;   delete pUnicode;   return rt;   }   static string UnicodeToUTF8( const wstring& str )   {   char* pElementText;   int iTextLen;   // wide char to multi char   iTextLen = WideCharToMultiByte( CP_UTF8, 0, str.c_str(), -1, NULL, 0, NULL, NULL );   pElementText = new char[iTextLen + 1];   memset( ( void* )pElementText, 0, sizeof( char ) * ( iTextLen + 1 ) );   WideCharToMultiByte( CP_UTF8, 0, str.c_str(), -1, pElementText, iTextLen, NULL, NULL );   string strText = pElementText;   delete[] pElementText;   return strText;   }   };

  [ 本帖最后由 zhaxg 于 2009-10-13 08:59 编辑 ]

读书人网 >其他相关

热点推荐