반응형
std::wstring NarrowToWide(const std::string& szNarrow) { int size = MultiByteToWideChar( CP_ACP, // code page 0, // character-type options szNarrow.c_str(), // string to map szNarrow.size(), // number of bytes in string NULL, // wide-character buffer 0 // size of buffer ); size++; WCHAR* pBuf = new WCHAR[size]; memset(pBuf,0,size*sizeof(WCHAR)); int size2 = MultiByteToWideChar( CP_ACP, // code page 0, // character-type options szNarrow.c_str(), // string to map szNarrow.size(), // number of bytes in string pBuf, // wide-character buffer size // size of buffer ); std::wstring szWide; if(size2>0) szWide = pBuf; memset(pBuf,0,size*sizeof(WCHAR)); delete [] pBuf; pBuf = NULL; return szWide; } std::string WideToNarrow(const std::wstring& szWide) { BOOL bUsedDefaultChar=FALSE; int size = WideCharToMultiByte( CP_ACP, // code page 0, // character-type options szWide.c_str(), // string to map szWide.size(), // number of bytes in string NULL, // character buffer 0, // size of buffer NULL, &bUsedDefaultChar); size++; CHAR* pBuf = new CHAR[size]; memset(pBuf,0,size*sizeof(CHAR)); bUsedDefaultChar=FALSE; int size2 = WideCharToMultiByte( CP_ACP, // code page 0, // character-type options szWide.c_str(), // string to map szWide.size(), // number of bytes in string pBuf, // character buffer size, // size of buffer NULL, &bUsedDefaultChar); std::string szNarrow; if(size2>0) szNarrow = pBuf; memset(pBuf,0,size*sizeof(CHAR)); delete [] pBuf; pBuf = NULL; return szNarrow; }
반응형
'c++ > MFC' 카테고리의 다른 글
[MFC] CEdit 에디트 박스 KillFocus, 포커스 제거 (0) | 2018.12.21 |
---|---|
[MFC] Edit 에디트 입력 제한하기. SetLimitText는 길이만, 바이트 단위로 제한 안되므로... (0) | 2018.12.19 |
[MFC] Office CommandBars 추가하는 COM 에드인이 최초 실행시에만 로드되는 문제/Office Context Menu CommandBars Addin loads only initial start up. (0) | 2018.12.13 |
[MFC] error C2248: 'CObject::CObject' 해결 (0) | 2018.12.13 |
[MFC] 비트맵 배경을 스크롤하기 (0) | 2018.12.12 |