CString , BSTR ,char ,CComVariant 간의 자료형변환
#include

CString bstrToCString(BSTR bstr)
{
char* pbstr;
USES_CONVERSION; //convert를 위한 매크로
pbstr=OLE2A(bstr); //bstr을 char로 convert
return CString(pbstr);
}

BSTR CStringTobstr(CString str)
{
return str.AllocSysString(); //CString을 bstr로 convert
}

[bstr-> char*]
BSTR inputdata;
char *pbstr;
pbstr=OLE2A(inputdata);

[char* -> bstr]
TCHAR szTitle[ 512 ];
_bstr_t bstrText = szTitle;
*bstrTitle = bstrText.copy();


//CString ==> CComVariant로 변환
CComVariant out(str.AllocSysString()); or CComVariant out(str);


//CComVariant ==> CString
CString szTmp;
szTmp = comvariant.bstrVal;



VARIANT VariantString(BSTR str)
{
VARIANT var;
VariantInit(&var);
V_BSTR(&var) = SysAllocString(str);
V_VT(&var) = VT_BSTR;
return var;
}

+ Recent posts