描述:
            程序简化后如下:
void CCtrlPanel::TestRead()
{
	HRESULT hr;
	try
	{
		hr=m_recordset->Open("select * from GateState1",
			DataBaseSource,adOpenKeyset,adLockOptimistic,adCmdText);
		if(SUCCEEDED(hr))
		{
			_variant_t Opendegree;
			Opendegree=m_recordset->GetCollect("Opendegree");
			float fOpendegree=(float)Opendegree;
			char str[6];
			sprintf(str,"%.2f米",fOpendegree);
//			AfxMessageBox(str);
			GetDlgItem(IDC_USER)->SetWindowText(str);
			m_recordset->Close();
		}
	}
	catch(_com_error &e)
	{
		MessageBox((char*)e.Description(),"查询数据库错误!",MB_ICONERROR | MB_OK);
	}
}
上面的函数用定时器定时调用,当把上面的GetDlgItem(IDC_USER)->SetWindowText(str);换成AfxMessageBox(str);后,疯狂弹出错误,
只能强行结束,错误是通过MessageBox((char*)e.Description(),"查询数据库错误!",MB_ICONERROR | MB_OK);弹出来的,内容是:
对象打开时,不允许操作!
请问为什么?
解决方案1:
char str[6]是不是分配的空间太小了?

