2013-02-01 55 views
3

我填充組合框:CComboBox :: GetLBText返回垃圾

while((pHPSet = pHPTable->GetNext()) != NULL) 
    {  
     CString str = pHPSet->GetName(); 
      // I am normally using str but to proove that this is 
      // not the problem I am using "a" 
     m_comboBaseHP.AddString(_T("a")); 
    } 

現在我想讀的組合框:

if(m_comboBaseHP.GetCount() > 0) 
{ 
    CString csHPName = _T(""); 
    m_comboBaseHP.GetLBText(0, csHPName); 
    // This is the ms way but ReleaseBuffer causes a crash 
    //CString str = _T(""); 
    //int n = m_comboBaseHP.GetLBTextLen(0); 
    //m_comboBaseHP.GetLBText(0, str.GetBuffer(n)); 
    //str.ReleaseBuffer(); 

    // Do whatever with csHPName 
} 

的問題是,csHPName顯示在調試一些中國的跡象。我假設這是內存垃圾。這發生在同一個方法中。這發生在預抽。帖子繪製相同的問題。這發生在調試和發佈。我不明白這是怎麼發生的,因爲我實際上並沒有使用指針。

+0

請任何內存泄漏在你的代碼 – Riskhan

+1

@kTekkie我很欣賞你的意見,但是,這是數百萬行代碼的產品,我相信冥冥中有一些。你能不能更具體地說明爲什麼我要找他們。這是通用的。 – Martin

回答

5

顯然有必要設置該物業組合框的字符串爲True。

+0

我使用的是[自定義](http://www.codeproject.com/Articles/489189/Group-Combo-Box)組合框,並面臨着同樣的問題,但我不能設置*具有字符串*爲'FALSE'。有沒有其他可能的解決方案? –