소스 팁/C, C++, C#
BSTR 변환
인디개발자
2017. 12. 29. 09:25
BSTR <-> CString
CString BSTRToCString(BSTR bstr) { char* pbstr; USES_CONVERSION; // <atlconv.h>, convert를 위한 macro pbstr = OLE2A(bstr); // BSTR -> char return CString(bstr); } BSTR CStringToBSTR(CString str) { return str.AllocSysString(); // CString to BSTR } |
BSTR <-> char*
// BSTR to char* BSTR bstr char* pbstr; USES_CONVERSION; // <atlconv.h>, convert를 위한 macro pbstr = OLE2A(bstr); // BSTR -> char // char to BSTR TCHAR szString[512]; _bstr_t bstr_string = szString; BSTR bstr *bstr = bstr_string.copy(); |
CString <-> CComVariant
// CString -> CComVariant CString str; CComVariant out(str.AllocSysString()); or CComVariant out(str); // CComVariant -> CString str = out.bstrVal; |
VARIANT
VARIANT BSTRToVARIANT(BSTR bstr) { VARIANT var; VariantInit(&var) V_BSTR(&var) = SysAllocString(&bstr); V_VT(&var) = SysAllocString(&bstr); return var; } |
출처: http://darkblitz.tistory.com/120 [긍정적 사고]
반응형