/* 说明: 将 宽字节wchar_t* 转换 单字节char* 参数: szStr是源字符串,pResult,为目标字符串, maxLen为pResult所指向的内存空间的最大长度 */ char* UnicodeToAnsi( const wchar_t* szStr ,char *pResult ,int maxLen) { if(NULL == pResult) return NULL; int nLen = WideCharToMultiByte( CP_ACP, 0, szStr, -1, NULL, 0, NULL, NULL ); if(0 == nLen) { return NULL; } if(nLen >= maxLen) nLen = maxLen; WideCharToMultiByte( CP_ACP, 0, szStr, -1, pResult, nLen, NULL, NULL ); return pResult; } /* 说明: 将 单字节char* 转换为 宽字节 wchar* 参数: szStr是源字符串,pResult,为目标字符串, maxLen为pResult所指向的内存空间的最大长度 */ wchar_t* AnsiToUnicode( const char* szStr,wchar_t *pResult ,int maxLen ) { if(NULL == pResult) return NULL; int nLen = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szStr, -1, NULL, 0 ); if(0 == nLen) { return NULL; } //wchar_t* pResult = new wchar_t[nLen]; if(nLen >= maxLen) nLen = maxLen; nLen = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, szStr, -1, pResult, nLen ); if(0 == nLen) { return NULL; } return pResult; }