CComboBox::GetLBText returns garbage
c++, mfc
Solution
Apparently it is necessary to set the property Has Strings of the combobox to True.
Problem
I am filling a combobox: ``` 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")); } ``` Now I am trying to read the combobox: ``` 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 } ``` The problem is that csHPName shows in the Debugger some Chinese signs. I am assuming this is memory garbage. This happens in the same Method. This happens pre draw. Post draw the same issue. This happens in Debug and Release. I don't understand how this can happen since I am not actually working with pointers.