我正在填写一个组合框:
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 在调试器中显示了一些中文标志。我假设这是内存垃圾。这发生在相同的方法中。这发生在抽奖前。后画同样的问题。这发生在调试和发布中。我不明白这是怎么发生的,因为我实际上并没有使用指针。