Я получаю эту ошибку, когда пишу данные Cstring в файл xls в VC++. На самом деле я читаю данные из другого столбца в том же файле. После выполнения некоторых операций я помещаю его обратно в другой столбец в том же файле, для небольших данных, которые он принял. Как только приходит сообщение большего размера, оно генерирует исключение и ломается.
Код функции вставлен ниже:
void CLoadOcxDlg::read(std::string excelFile, int sheetIndex, bool header, std::string csvFile)
{
clock_t t1 = clock();
std::cout << "reading " << excelFile;
if(FAILED(::CoInitialize(NULL))) return;
_RecordsetPtr pSchema = NULL;
_RecordsetPtr pRec = NULL;
int cellCount = 0;
try
{
_bstr_t connStr(makeConnStr(excelFile, header).c_str());
TESTHR(pRec.CreateInstance(__uuidof(Recordset)));
TESTHR(pRec->Open(sqlSelectSheet(connStr, sheetIndex).c_str(), connStr, adOpenStatic, adLockOptimistic, adCmdText));
//TESTHR(pRec->Open(sqlSelectSheet(connStr, sheetIndex).c_str(), connStr, adOpenKeyset, adLockUnspecified, adCmdText));
std::ofstream stream(csvFile.c_str());
while(!pRec->adoEOF)
{
for(long i = 8; i < pRec->Fields->GetCount(); )//++i)
{
CString Label = pRec->Fields->GetItem("LABEL/SMI")->Value;
if((Label == "AA") || (Label == "A6") || (Label == "BA") || (Label == "B6"))
{
CString str = pRec->Fields->GetItem(i + 8)->Value;
//_variant_t v = pRec->Fields->GetItem(i+8)->Value;
//if((v.vt == VT_R8) || (v.vt == VT_BSTR))
CString baseString = "/";
{
if(str.GetLength())
{
int iCount = 0;
iCount = str.ReverseFind('/');
//Removing the Message part before '/'
str.Delete(0,iCount+1);
//CString baseString = "/";
baseString.Append(Label);
baseString.Append(" ");
baseString.Append(str);
baseString.Delete(baseString.GetLength() - 5,baseString.GetLength());
//pRec->Fields->GetItem(i + 9)->Value = _variant_t(baseString);
}
m_strDecodedMesg = m_ctrlDecoder.DecodeMessage(baseString);
long length = m_strDecodedMesg.GetLength();
m_strDecodedMesg.Insert(0,'"');
m_strDecodedMesg.Insert((m_strDecodedMesg.GetLength()+1),'"');
stream <<m_strDecodedMesg
**pRec-="">
Fields->GetItem("DECODED_MESSAGE")->Value = _variant_t(m_strDecodedMesg);**
pRec->Fields->GetItem("LENGTH")->Value = _variant_t(length);
DataTypeEnum ctype;
ctype = pRec->Fields->GetItem("DECODED_MESSAGE")->GetType();
TESTHR(pRec->Update());
}
++cellCount;
}
else
{
stream << _T("\" \"");
}
stream << std::endl;
pRec->MoveNext();
/*if(pRec->adoEOF)
MessageBox("Decoding is Completed");*/
}
}
}
catch(_com_error &e)
{
_bstr_t bstrDescription(e.Description());
CharToOem(bstrDescription, bstrDescription);
std::cout << bstrDescription << std::endl;
}
//if(connStr->State == adStateOpen) connStr->Close();
::CoUninitialize();
clock_t t2 = clock();
double t = (double)(t2 - t1) / CLOCKS_PER_SEC;
std::cout << ": " << t << " sec; " << cellCount / t << " cells/sec" << "; see " << csvFile << std::endl;
}