Mensaje    Asunto: Ayuda con Exception code: 0xc0000374 Responder citando

buenos días a todos estoy desarrollando una pequeña aplicación que extrae datos de una hoja de Excel pero me está generando una excepción que no soy capaz de manejar y hace que mi aplicación se cierre he buscado y tratado varias soluciones y no he podido dar con el problema.

Buscando en la red he encontrado esto pero no puedo solucionarlo.

Link 1:
http://social.technet.microsoft.com/Forums/windows/en-US/578396fd-29c0-4dd3-b002-5e2e8df1b398/exception-code-0xc0000374?forum=w7itprogeneral

Link 2:
http://connect.microsoft.com/VisualStudio/feedback/details/664497/cant-catch-0xc0000374-exception-status-heap-corruption

he probado con diferentes versiones de sistema operativo y office y solo en XP no sucede este problema, también he probado con BCB6 y RAD XE4 y 5 pero se sigue presentando el problema.

BCB6


RAD XR5


y este es la rutina la cual se ejecuta sin problema y la excepción se produce al momento de salir de ella.

Código:

//---------------------------------------------------------------------------
void TForm1::cargar_desembolsos()
{
 std::auto_ptr<TADOQuery> ADOQuery1( new TADOQuery(NULL) );
 std::auto_ptr<TProgressBar> ProgressBar1( new TProgressBar(this) );
 TADOQuery *ADOQueryM;

 bool error = false;
 long int idCon = 0, idDoc, idPol = 0, iconos = MB_OK | MB_ICONINFORMATION;
 Variant xlApp, xlLibro, xlHoja, xlCelda, xlRango, UltimaCelda, datos;
 WideString OrigenPath;
 String dato, rutaLogs, sSenFox, msn = "Proceso terminado con éxito.";
 double fmonto;

 ProgressBar1->Parent=StatusBar1;
 ProgressBar1->Width=StatusBar1->Panels->Items[1]->Width-2;
 ProgressBar1->Left=StatusBar1->Panels->Items[0]->Width+2;
 ProgressBar1->Top=2;
 ProgressBar1->Height=StatusBar1->Height-2;
 StatusBar1->Panels->Items[0]->Text = "Procesando Excel";

 ADOQuery1->ConnectionString = ConexionDatos;
 InteresesDevengados1->Tag = 0;
 if( !Edit1->Text.IsEmpty() ){
    OrigenPath = Edit1->Text;
    xlApp = CreateOleObject("Excel.Application");
    xlApp.OlePropertySet("Visible", false);
    xlLibro = xlApp.OlePropertyGet("Workbooks");
    xlLibro.OleProcedure("Open", OrigenPath.c_bstr(), 0, true);
    xlHoja = xlApp.OlePropertyGet("ActiveSheet");

    if (xlHoja.IsEmpty()){
      xlApp.OleProcedure("Quit");
    }

    //Busca la última fila y columna que tienen datos:
    xlCelda = xlHoja.OlePropertyGet("Cells");
    const xlCellTypeLastCell = 11;
    UltimaCelda = xlCelda.OleFunction("SpecialCells", xlCellTypeLastCell);
    long int UltimaFila = UltimaCelda.OlePropertyGet("Row");
    long int UltimaCol = UltimaCelda.OlePropertyGet("Column");
    long int Fila = 1; //es la primera fila en la que hay datos
    long int Columna = 1;

    try{
      ADOQueryM = new TADOQuery(NULL);
      // Seleccionamos el princio del rango
      xlRango = xlHoja.OlePropertyGet("Cells", Fila, Columna);
      // Adaptamos el tamaño del rango
      xlRango = xlRango.OlePropertyGet("Resize", UltimaFila, UltimaCol);
      // Recibimos el array de datos
      datos = xlRango.OlePropertyGet("Value");
      // Cerramos Excel
      xlApp.OleProcedure("Quit");
      xlApp = Unassigned;
      xlLibro = Unassigned;
      xlHoja = Unassigned;
      xlCelda = Unassigned;
      xlRango = Unassigned;
      UltimaCelda = Unassigned;
      Memo1->Clear();
      Memo1->Lines->Add("Fila   \tCuenta  Capital   \tInteres   \t\tIVA   \t\tTotal");
      //El primer dato es la fecha
      //dato = datos.GetElement(2, 3).AsType(varString); //No tiene el formato correcto

      ProgressBar1->Max = UltimaFila ;
      for(int fila = 1; fila < UltimaFila+1; fila++){
         ProgressBar1->Position++;
         dato = datos.GetElement(fila, 2).AsType(varString);
         if( !dato.IsEmpty() ){
            if( esConcepto( dato.UpperCase(), idCon ) ){
               if( !existeCon( dato.UpperCase(), idDoc, idPol ) ){
                  creaPol( idCon, idPol , "pol_des");
               }
            }else {
               if( esMovimiento( dato, datos.GetElement(fila, 4).AsType(varString) ) ){
                  fmonto = StringReplace(StringReplace(datos.GetElement(fila, 4).AsType(varString),"$","",TReplaceFlags() << rfReplaceAll),",","",TReplaceFlags() << rfReplaceAll).ToDouble();

                  sSenFox = "SELECT ma.cuenta, ma.tipomov, ma.concepto, ma.nombre, ";
                  sSenFox += "porce, ma.referencia FROM Conceptos AS c ";
                  sSenFox += "INNER JOIN Movimientosa AS ma ON idasiento = pol_des ";
                  sSenFox += "WHERE c.id = ";
                  sSenFox += idCon;
                  ADOQueryM->ConnectionString = ConexionComunes;
                  ADOQueryM->SQL->Clear();
                  ADOQueryM->SQL->Add(sSenFox);
                  ADOQueryM->Prepared = true;
                  ADOQueryM->Open();

                  if( !ADOQueryM->IsEmpty() ){
                     if( fmonto > 0.1 ){
                        creaMovPol( idPol, fmonto, 0.00, ADOQueryM, dato );
                        ADOQueryM->Next();
                        creaMovPol( idPol, 0.00, fmonto, ADOQueryM, dato );
                     }
                  }
                  ADOQueryM->Close();
               }
            }
         }
         Application->ProcessMessages();
      }
    }__finally{
       datos = Unassigned;
       BitBtn1->Enabled = true;
       if( error ){
         msn = "Se encontraron movimientos descuadrados.\nConsulte la bitácora para más información.\n";
         iconos =MB_OK | MB_ICONWARNING;
         rutaLogs = ExtractFilePath(Application->ExeName);
         rutaLogs += "logs\\";
         rutaLogs += FormatDateTime("dd-mm-yyyy_hh-nn-ss", Now());
         rutaLogs += ".txt";
         msn += rutaLogs;
         Memo1->Lines->SaveToFile( rutaLogs );
       }
       Application->MessageBoxW(msn.c_str(),L"Información", iconos);
       StatusBar1->Panels->Items[0]->Text = "";
       ADOQueryM->Close();
       ADOQuery1->Close();

       delete ADOQueryM;
    }
 }

 return;
}
//---------------------------------------------------------------------------


Saludos y gracias por su tiempo.
_________________
[img]http://folding.extremeoverclocking.com/sigs/sigimage.php?un=snupoo&t=86565/sigimage.gif[/img]
A programar se aprende programando