I work in Windows XP using Visual Studio 6 (yes, I know, the old one), building / maintaining the C ++ DLL. I ran into a problem when fopen was unable to open an existing file, it always returns NULL.
I tried:
- Checking errno and _doserrno, setting both values ββto zero and then checking them again, both remain equal to zero, and so GetLastError () does not report errors. I know that fopen is not required to install errno when it encounters an error according to the C standard.
- Hardcoding is a file path that is not relative.
- I tried on another development machine, which had the same result.
It is really strange that CreateFile works, and the file can be read using ReadFile. We believe this works in release builds, however we also see very strange behavior in other areas of the application, and we are not sure if this is related.
The code below, I do not see anything strange, it looks quite standard for me. The original file has not changed for less than six months.
HRESULT CDataHandler::LoadFile( CStdString szFilePath ) { //Code FILE* pFile; if ( NULL == ( pFile = fopen( szFilePath.c_str(), "rb") ) ) { return S_FALSE; } //More code }
c ++ windows file-io fopen vc6
void
source share