【GUI】wxWidgets(旧wxWindows) その4【サイザー】

715デフォルトの名無しさん
WCHAR *SJIS2WCS(string sjis)
{
if(sjis == "") return NULL;
int wlen = MultiByteToWideChar(CP_ACP, 0, sjis.c_str(), -1, NULL, 0);
WCHAR *wbuf = new WCHAR[wlen + 1];
if(wbuf == NULL) return NULL;
*wbuf = L'\0';
if(MultiByteToWideChar(CP_ACP, 0, sjis.c_str(), -1, wbuf, wlen) <= 0){
delete [] wbuf;
return NULL;
}
return wbuf;
}
string WCS2SJIS(WCHAR *wbuf)
{
if(wbuf == NULL || wbuf[0] == L'\0') return "";
int slen = WideCharToMultiByte(CP_ACP, 0, wbuf, -1, NULL, 0, NULL, NULL);
char *sbuf = (char *)_malloca((slen + 1) * sizeof(char));
if(sbuf == NULL) return "";
*sbuf = '\0';
if(WideCharToMultiByte(CP_ACP, 0, wbuf, -1, sbuf, slen, NULL, NULL) <= 0) return "";
sbuf[slen] = '\0';
return sbuf;
}