ATL字符串总结和转换

1.CString 转 BSTR

CString s;
...
BSTR bstr = s.AllocSysString();

 

2.BSTR在字符串之前放上字符数,这样处理起来有效率得多,

这也决定了BSTR不能直接赋值:BSTR bstr = "...";//这是错误的

 

ATL封装了CComBSTR类

 

3.long 转 ComBSTR

    long count = 0;
    pSealArray->get_Count(&count);
    wchar_t* longStr = (wchar_t *) malloc(16*sizeof(wchar_t));
    swprintf(longStr, L"%d", count); 
    MessageBoxW(NULL,CComBSTR( longStr), L"", 0);
    free(longStr);    

 

posted on 2015-03-01 23:02  aoun  阅读(249)  评论(0)    收藏  举报