我正在填充一个组合框:
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在调试器中显示了一些中文符号。我假设这是内存垃圾。这发生在同一个方法中。这种情况发生在预抽。发布同样的问题。这发生在Debug和Release中。我不明白这是怎么发生的,因为我实际上并没有使用指针。
答案 0 :(得分:5)
显然有必要将组合框的属性Has Strings设置为True。