Hijo C++ y Windows

07/07/2005 - 04:27 por FGarzon | Informe spam
Hola colegas, requiero de un parde manitos, la una es para saber como ejecuto
desde Turbo c++ para windows un ejecutable como proceso hijo, por ejemplo
ejecutar un programa como winword.exe y cuado se cierre winword.exe se
ejecute el resto de lineas de c++, y la otra es para saber el comando con el
que copia un archivo.

Gracias por su ayuda.

Preguntas similare

Leer las respuestas

#1 Octavio Hernandez
14/07/2005 - 00:27 | Informe spam
Mira este artículo:

http://bdn.borland.com/article/0,14...15,00.html

Slds - Octavio

"FGarzon" escribió en el mensaje
news:
Hola colegas, requiero de un parde manitos, la una es para saber como
ejecuto
desde Turbo c++ para windows un ejecutable como proceso hijo, por ejemplo
ejecutar un programa como winword.exe y cuado se cierre winword.exe se
ejecute el resto de lineas de c++, y la otra es para saber el comando con
el
que copia un archivo.

Gracias por su ayuda.


Respuesta Responder a este mensaje
#2 Fernando Marin
15/07/2005 - 17:44 | Informe spam
Hola Garzon

Para copiar un archivo usa la función
CopyFile de SDK
tambien puedes hacerte una lees el archivo y lo guardas

algo parecido a las siguientes funciones

una cosa importante las siguientes funciones son solo a titulo de ejemplo,
que solo funcionan con formato texto (*.txt) y no con archivos binarios.

un saludo
Fernando Marin



#include "stdafx.h"

BOOL CreaFichero(CString sNombreFichero,CString sTexto,BOOL bMsgError)
{
CFileException eOpen;
char *texto=NULL;
CString sError=_T("");
TRY
{
CFile FicheroEscritura;
if (FicheroEscritura.Open(sNombreFichero,CFile::modeCreate |
CFile::modeWrite,&eOpen))
{
UINT tam=0; //
tam=sTexto.GetLength();
/* char * */texto=new char[tam+1];
for(UINT n=0;n<tam;n++)
texto[n]=sTexto.GetAt(n);
texto[tam]=0;
FicheroEscritura.Write(texto,tam+1);
}
else
{
if(bMsgError)
{
switch(eOpen.m_cause )
{
case CFileException::none:sError=_T(" No error occurred."); break;
case CFileException::generic:sError=_T(" An unspecified error
occurred."); break;
case CFileException::fileNotFound: sError=_T(" The file could not be
located."); break;
case CFileException::badPath: sError=_T(" All or part of the path is
invalid."); break;
case CFileException::tooManyOpenFiles: sError=_T(" The permitted
number of open files was exceeded."); break;
case CFileException::accessDenied: sError=_T(" The file could not be
accessed."); break;
case CFileException::invalidFile: sError=_T(" There was an attempt to
use an invalid file handle."); break;
case CFileException::removeCurrentDir: sError=_T(" The current
working directory cannot be removed."); break;
case CFileException::directoryFull: sError=_T(" There are no more
directory entries."); break;
case CFileException::badSeek: sError=_T(" There was an error trying
to set the file pointer."); break;
case CFileException::hardIO: sError=_T(" There was a hardware
error."); break;
case CFileException::sharingViolation: sError=_T(" SHARE.EXE was not
loaded, or a shared region was locked."); break;
case CFileException::lockViolation: sError=_T(" There was an attempt
to lock a region that was already locked."); break;
case CFileException::diskFull: sError=_T(" The disk is full.");
break;
case CFileException::endOfFile: sError=_T(" The end of file was
reached."); break;
default: sError=_T(" Error desconocido ");
}
sError=_T(" Error al escribir el archivo debido a: ")+sError;
AfxMessageBox(sError);
}
return FALSE;
}
FicheroEscritura.Close();
}
CATCH(CFileException,e)
{
if(bMsgError)
{
switch(e->m_cause )
{
case CFileException::none:sError=_T(" No error occurred."); break;
case CFileException::generic:sError=_T(" An unspecified error
occurred."); break;
case CFileException::fileNotFound: sError=_T(" The file could not be
located."); break;
case CFileException::badPath: sError=_T(" All or part of the path is
invalid."); break;
case CFileException::tooManyOpenFiles: sError=_T(" The permitted
number of open files was exceeded."); break;
case CFileException::accessDenied: sError=_T(" The file could not be
accessed."); break;
case CFileException::invalidFile: sError=_T(" There was an attempt to
use an invalid file handle."); break;
case CFileException::removeCurrentDir: sError=_T(" The current working
directory cannot be removed."); break;
case CFileException::directoryFull: sError=_T(" There are no more
directory entries."); break;
case CFileException::badSeek: sError=_T(" There was an error trying to
set the file pointer."); break;
case CFileException::hardIO: sError=_T(" There was a hardware
error."); break;
case CFileException::sharingViolation: sError=_T(" SHARE.EXE was not
loaded, or a shared region was locked."); break;
case CFileException::lockViolation: sError=_T(" There was an attempt
to lock a region that was already locked."); break;
case CFileException::diskFull: sError=_T(" The disk is full."); break;
case CFileException::endOfFile: sError=_T(" The end of file was
reached."); break;
default: sError=_T(" Error desconocido ");
}
sError=_T(" Error al escribir el archivo debido a: ")+sError;
AfxMessageBox(sError);
}
delete [] texto;
return FALSE;
}
END_CATCH

delete [] texto;
return TRUE;
}

BOOL LeeFichero(CString sNombreFichero,CString &sTexto,BOOL bMsgError)
{
CFileException eOpen;
char *texto=NULL;
CString sError=_T("");
sTexto=_T("");
TRY
{
CFile FicheroLectura;
if (FicheroLectura.Open(sNombreFichero,CFile::modeRead,&eOpen))
{

UINT uActual;
UINT uVar=1;
UINT tam = (UINT)(FicheroLectura.GetLength()); //
texto=new char[tam+1];
uActual=FicheroLectura.Read(texto,tam);
texto[tam];
sTexto=texto;
}
else
{
if(bMsgError)
{
switch(eOpen.m_cause )
{
case CFileException::none:sError=_T(" No error occurred."); break;
case CFileException::generic:sError=_T(" An unspecified error
occurred."); break;
case CFileException::fileNotFound: sError=_T(" The file could not be
located."); break;
case CFileException::badPath: sError=_T(" All or part of the path is
invalid."); break;
case CFileException::tooManyOpenFiles: sError=_T(" The permitted
number of open files was exceeded."); break;
case CFileException::accessDenied: sError=_T(" The file could not be
accessed."); break;
case CFileException::invalidFile: sError=_T(" There was an attempt to
use an invalid file handle."); break;
case CFileException::removeCurrentDir: sError=_T(" The current
working directory cannot be removed."); break;
case CFileException::directoryFull: sError=_T(" There are no more
directory entries."); break;
case CFileException::badSeek: sError=_T(" There was an error trying
to set the file pointer."); break;
case CFileException::hardIO: sError=_T(" There was a hardware
error."); break;
case CFileException::sharingViolation: sError=_T(" SHARE.EXE was not
loaded, or a shared region was locked."); break;
case CFileException::lockViolation: sError=_T(" There was an attempt
to lock a region that was already locked."); break;
case CFileException::diskFull: sError=_T(" The disk is full.");
break;
case CFileException::endOfFile: sError=_T(" The end of file was
reached."); break;
default: sError=_T(" Error desconocido ");
}
sError=_T(" Error al escribir el archivo debido a: ")+sError;
AfxMessageBox(sError);
}
return FALSE;
}
FicheroLectura.Close();
}
CATCH(CFileException,e)
{
if(bMsgError)
{
switch(e->m_cause )
{
case CFileException::none:sError=_T(" No error occurred."); break;
case CFileException::generic:sError=_T(" An unspecified error
occurred."); break;
case CFileException::fileNotFound: sError=_T(" The file could not be
located."); break;
case CFileException::badPath: sError=_T(" All or part of the path is
invalid."); break;
case CFileException::tooManyOpenFiles: sError=_T(" The permitted
number of open files was exceeded."); break;
case CFileException::accessDenied: sError=_T(" The file could not be
accessed."); break;
case CFileException::invalidFile: sError=_T(" There was an attempt to
use an invalid file handle."); break;
case CFileException::removeCurrentDir: sError=_T(" The current working
directory cannot be removed."); break;
case CFileException::directoryFull: sError=_T(" There are no more
directory entries."); break;
case CFileException::badSeek: sError=_T(" There was an error trying to
set the file pointer."); break;
case CFileException::hardIO: sError=_T(" There was a hardware
error."); break;
case CFileException::sharingViolation: sError=_T(" SHARE.EXE was not
loaded, or a shared region was locked."); break;
case CFileException::lockViolation: sError=_T(" There was an attempt
to lock a region that was already locked."); break;
case CFileException::diskFull: sError=_T(" The disk is full."); break;
case CFileException::endOfFile: sError=_T(" The end of file was
reached."); break;
default: sError=_T(" Error desconocido ");
}
sError=_T(" Error al escribir el archivo debido a: ")+sError;
AfxMessageBox(sError);
}
delete [] texto;
return FALSE;
}
END_CATCH

delete [] texto;
return TRUE;
}



Fernando Marin



"FGarzon" escribió en el mensaje
news:
Hola colegas, requiero de un parde manitos, la una es para saber como
ejecuto
desde Turbo c++ para windows un ejecutable como proceso hijo, por ejemplo
ejecutar un programa como winword.exe y cuado se cierre winword.exe se
ejecute el resto de lineas de c++, y la otra es para saber el comando con
el
que copia un archivo.

Gracias por su ayuda.


email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida