C Language String Types and Classes
String Type | Description |
char/wchar/TCHAR | The C strings for ANSI and Unicode |
CString | The C++/MFC class wrapper for C strings |
BSTR | The Visual Basic string type |
_bstr_t | A C++ class wrapper for the Visual Basic string type |
CComBSTR | Yet another C++ class wrapper for the Visual Basic string type used predominately in ATL code |
Demo Code
BSTR to CString and CString to BSTR
void BSTRtoCString(BSTR bStr){ void CStringtoBSTR() csStr = "Hello BelieveIT!"; BSTR bStr = csStr.AllocSysString(); BSTRtoCString(bStr); ::SysFreeString(bStr); //finished using the BSTR } |
Base Code
BSTR GetBSTR() BSTR bstr; bstr = bstrt.copy(); return bstr; CComBSTR GetComBSTR() return bstr; } void ShowBSTR(BSTR bstr) CString cstr; cstr.Format(_T("%s"),(LPCTSTR)bstrt); AfxMessageBox(cstr); } |
Conversions Code
_bstr_t BSTRto_bstr_t() _bstr_t bstrFinal(bstr); ShowBSTR(bstrFinal); bstrFinal = bstr; return bstrFinal;
BSTR _bstr_ttoBSTR() BSTR bstrFinish; bstrFinish = bstr.copy(); ShowBSTR(bstrFinish); bstrFinish = bstr; return bstrFinish; }
BSTR CComBSTRtoBSTR() BSTR bstrFinish; bstrFinish = bstr; ShowBSTR(bstrFinish); bstrFinish = bstr.Copy(); return bstrFinish; }
CComBSTR _bstr_ttoCComBSTR() CComBSTR bstrFinish; bstrFinish.AppendBSTR(bstr); return bstrFinish; }
CString BSTRtoCString() bstr = GetBSTR(); TCHAR szFinal[255] = {0,}; _stprintf(szFinal, _T("%s"), (LPCTSTR)bstr); AfxMessageBox(szFinal); _bstr_t bstrIntermediate(bstr); CString strFinal; _stprintf(szFinal, _T("%s"), (LPCTSTR)bstrIntermediate); strFinal.Format(_T("%s"),(LPCTSTR)bstrIntermediate); return strFinal; }
CString _bstr_ttoCString() TCHAR szFinal[255] = {0,}; _stprintf(szFinal,_T("%s"),(LPCTSTR)bstr); return szFinal;
LPCTSTR CComBSTRtoLPCTSTR() CComBSTR bstr("This is Converting string"); _bstr_t bstrIntermediate(bstr); TCHAR szFinal[255] = {0,}; _stprintf(szFinal, _T("%s"),(LPCTSTR)bstrIntermediate); return szFinal;
_bstr_t LPCTSTRto_bstr_t() _bstr_t bstrFinal(szStart); ShowBSTR(bstrFinal); bstrFinal = szStart; return bstrFinal;
CComBSTR LPCTSTRtoComBSTR() CComBSTR bstrFinal(szStart); ShowBSTR(bstrFinal); bstrFinal.Empty(); bstrFinal.Append(szStart); return bstrFinal; |
[ Reference ]
http://blog.naver.com/mismir?Redirect=Log&logNo=40013446819 |
http://www.codeproject.com/Articles/1282/Easy-way-to-manipulate-BSTR-using-CString-class |
'IT 나라 > 프로그램 이야기' 카테고리의 다른 글
그루보드5 설치 방법, 그루보드5 시작 (0) | 2016.05.16 |
---|---|
그누보드5 관리자 비밀번호 변경 방법 (0) | 2016.05.04 |
Sliding window (0) | 2013.07.02 |
Window Event Sequence (0) | 2013.06.12 |
원도우 "서버 작업 중" 대화상자 출력 문제 해결 방법 (0) | 2013.05.03 |