#keywords BSTR,C++,CString,MFC [[TableOfContents]] === 'CString' to 'BSTR': === Use the AllocSysString member function of the CString: Code: {{{#!gcode CString str("Hello"); BSTR bstr = str.AllocSysString(); }}} If you pass the 'BSTR' to some OLE function, this will normally free the 'BSTR' memory when done with it. If you use the 'BSTR' by yourself, dont forget to call '::SysFreeString()' when you're done with it. Code: {{{#!gcode ::SysFreeString(bstr); }}} === 'BSTR' to 'CString': === You will mostly need this when you have some OLE function that returns a 'BSTR'. Such an OLE Function will basically do something like this: Code: {{{#!gcode HRESULT SomeOLEFunction(BSTR& bstr) { bstr = ::SysAllocString(L"Hello"); return S_OK; } }}} Use a temporary variable of the type '_bstr_t' to wrap the 'BSTR'. This way you handle both the 208 and make sure that you have no memory leak: Code: {{{#!gcode BSTR bstr; SomeOLEFunction(bstr); _bstr_t tmp(bstr, FALSE); //wrap the BSTR CString str(static_cast(tmp)); //convert it AfxMessageBox(str, MB_OK, 0); // when tmp goes out of scope it will free the BSTRs memory }}} Note, that this won't work in a UNICODE build. === MFC가 아닌 경우. === #include #pragma comment (lib,"comsuppw.lib" ) === 기타 === What is this BSTR thing, and how does it differ from WCHAR* ? Here is Eric's Complete Guide To BSTR Semantics. http://blogs.msdn.com/b/ericlippert/archive/2003/09/12/52976.aspx