C++/형변환

CString <-> BSTR (Unicode , Multibyte)

람뫼 2018. 6. 7. 17:49

인터넷 대부분의 글에는 현재 프로젝트 환경이 Multibyte인지 Unicode인지 명시가 되어있지 않아


형변환 하기 힘든 경우가 많아서 작성한 글.. 이 예제는 Visual Studio 2013 MFC환경에서 제작되었음.




BSTR to CString


 

 BSTR to CString

 MultiByte

1
2
3
CString strTest = "QWERT";
BSTR szTest = strTest.AllocSysString();
CString strTest2 = (CString)szTest;
cs

 Unicode

1
2
BSTR szTest;
CString strTest2 = (CString)szTest;
cs



CString to BSTR


 

 CString to BSTR

MultiByte

1
2
CString strTest = "QWERT";
BSTR szTest = strTest.AllocSysString();
cs

 Unicode 

 

1
2
CString strTest = _T("QWERT");
BSTR szTest = strTest.AllocSysString();
cs


Unicode 및 Multibyte 둘다 동일하게 사용가능하다.