Microsoft KB Archive/181880

= PRB: "Access to an Unnamed File Was Denied" Error =

Article ID: 181880

Article Last Modified on 12/8/2003

-

APPLIES TO


 * Microsoft Visual C++ 4.0 Standard Edition
 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 5.0 Professional Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-



This article was previously published under Q181880



SYMPTOMS
You get the following error when calling CFile::Read:

Access to an unnamed file was denied.

If run under the Microsoft Visual C++ debugger, you will see the following error:

CFile exception: accessDenied, File Unknown, OS error information = 5



CAUSE
You are actually opening the file without read access. The following intuitively correct code causes the error: CFile cf; int data; cf.Open("myfile.dat", CFile::modeRead | CFile::modeWrite); cf.Write(&data, sizeof(int)); cf.Read(&data, sizeof(int));



RESOLUTION
Specify CFile::modeReadWrite instead of the logical OR of CFile::modeRead and CFile::modeWrite.



STATUS
This behavior is by design.

