BOOL LogErr( LPSTR lpmsg, DWORD err)
{
char buf[256];
HANDLE fh;
SYSTEMTIME st;
char lcfic[MAX_PATH];
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 255, NULL);
GetSystemTime( &st );
wsprintf( lcfic, "%s\\E%4.4d%02.2d%02.2d.txt", MyApp.myAppDir, st.wYear, st.wMonth, st.wDay);
if ( (fh = fopen(lcfic , "a+")) != NULL )
{
wsprintf( lcfic, "%02.2d:%02.2d:%02.2d ", lcfic );
fwrite( lcfic, 1, 9, fh );
fputs( lpmsg, fh );
fputs( buf, fh );
fwrite( "\r\n", 1, 2, fh );
fclose( fh );
}
return TRUE;
}
Using:
fh = CreateFile ("c:\\texto.txt", GENERIC_READ, FILE_SHARE_READ,0, OPEN_EXISTING, 0, 0);
if (!( INVALID_HANDLE_VALUE== fh )) {
} else LogErr( "Leyendo Fichero", GetLastError());