Before opening a file, it’s better to confirm if it exists.
WIN32_FIND_DATA fd; HANDLE hFile = ::FindFirstFile( fName, &fd );
if ( hFile == INVALID_HANDLE_VALUE ) { // file must not exist -- warn user
CString sMessage; sMessage.Format( "Could not find specified file/n/"%s/"", fName );
::MessageBox( NULL, sMessage, "Could Not Find File", MB_OK | MB_ICONEXCLAMATION );
::FindClose( hFile ); return;
}
::FindClose( hFile ); |