2017-01-28 43 views
0

2つのbstr_tを連結しようとしていますが、もう1つはint型です(これをbstr_tに変換してbstr(例: '#') + '1234'を '#12345'とします)。ただし、連結後、最終結果には「#」のみが含まれます。私はどこで間違いをしているのか分かりません。2つのBstr文字列を連結するためのC++コード

function(BSTR* opbstrValue) 
{ 
    _bstr_t sepStr = SysAllocString(_T("#")); 

    wchar_t temp_str[20]; // we assume that the maximal string length for displaying int can be 10 
    itow_s(imgFrameIdentity.m_nFrameId, temp_str, 10); 
    BSTR secondStr = SysAllocString(temp_str); 
    _bstr_t secondCComStr; 
    secondCComStr.Attach(secondStr); 

    _bstr_t wholeStr = sepStr + secondCComStr; 

    *opbstrValue = wholeStr.Detach(); 
} 

答えて

1

あなたは大幅に_bstr_tのコンストラクタを活用して、あなたの機能を簡素化することができます。オーバーロードのOneは入力パラメータとしてconst _variant_t&をとり、それを文字列として解析します。したがって、関数は次のようになります。

void function(BSTR* opbstrValue) 
{ 
    _bstr_t res(L"#"); 
    res += _bstr_t(12345); //replace with imgFrameIdentity.m_nFrameId 

    *opbstrValue = res.Detach(); 
}