Ich versuche gerade in Visual C eine einfache Funktion namens FileCopy zu implementieren (Name ist Programm). Ich bin schon soweit, dass die Datei erstellt wird, allerdings schaffe ich es nicht, den Dateiinhalt hineinzuschreiben.
Code: Alles auswählen
BOOL FileCopy(char *src, char *dst)
{
HANDLE hSrc, hDst;
LPDWORD lpSize = (LPDWORD)0;
hSrc = CreateFileA((LPCSTR)src,GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
if (hSrc == INVALID_HANDLE_VALUE)
{ PrintLastError();
Printf(src);
return FALSE;
}
hDst = CreateFileA((LPCSTR)dst,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,128,NULL);
if (hDst == INVALID_HANDLE_VALUE)
{ PrintLastError();
Printf(dst);
return FALSE;
}
GetFileSize(hSrc,lpSize);
if (ReadFile(hSrc,stdin,128,lpSize,NULL))
{
if(WriteFile(hDst,stdout,128,lpSize,NULL))
{ Printf("File copied successfully.\nPress ENTER to exit . . .");
return TRUE;
} else {
PrintLastError();
return FALSE;
}
} else {
PrintLastError();
return FALSE;
}
}
Gruß, Mok.