char 转wchar_t 和wchar_t转char
#include<Windows.h> #include<tchar.h> #include<stdio.h> char* WcharToChar(const wchar_t* wp) { char *m_char; int len= WideCharToMultiByte(CP_ACP,0,wp,wcslen(wp),NULL,0,NULL,NULL); m_char=new char[len+1]; WideCharToMultiByte(CP_ACP,0,wp,wcslen(wp),m_char,len,NULL,NULL); m_char[len]='\0'; return m_char; } wchar_t* CharToWchar(const char* c) { wchar_t *m_wchar; int len = MultiByteToWideChar(CP_ACP,0,c,strlen(c),NULL,0); m_wchar=new wchar_t[len+1]; MultiByteToWideChar(CP_ACP,0,c,strlen(c),m_wchar,len); m_wchar[len]='\0'; return m_wchar; }
vs2010下编译成功