我有以下代码块:
for( CarsPool::CarRecord &record : recs->GetRecords())
{
LVITEM item;
item.mask = LVIF_TEXT;
item.cchTextMax = 6;
item.iSubItem = 0;
item.pszText = (LPSTR)(record.getCarName().c_str()); //breakpoint on this line.
item.iItem = 0;
ListView_InsertItem(CarsListView, &item);
item.iSubItem = 1;
item.pszText = TEXT("Available");
ListView_SetItem(CarsListView, &item);
item.iSubItem = 2;
item.pszText = (LPSTR)CarsPool::EncodeCarType(record.getCarType());
ListView_SetItem(CarsListView, &item);
}
来自 Visual Studio 调试器的信息在这里:
为什么程序不能从字符串中读取字符?
测试表明它以这种方式工作:
MessageBox(hWnd, (LPSTR)(record.getCarName().c_str()), "Test", MB_OK);