views:

31

answers:

1

The following code snippet behaves in Debug mode (VC++ 2005) differently than in Release:

HANDLE hFileRead;
hFileRead = CreateFile(pszListFile,           //    lpFileName,
                       GENERIC_READ,          //    dwDesiredAccess,
                       FILE_SHARE_READ,       //    dwShareMode,
                       NULL,                  //    lpSecurityAttributes,
                       OPEN_EXISTING,         //    dwCreationDisposition,
                       FILE_ATTRIBUTE_NORMAL, //    dwFlagsAndAttributes,
                       0);                    //    hTemplateFile

In Release mode it works perfectly. In Debug mode, it it returns INVALID_HANDLE_VALUE in hFileRead. Further retrieving GetLastError() reveals system error 3:

ERROR_PATH_NOT_FOUND ("The system cannot find the path specified.")

This is weird. In Release mode it can find it but in Debug mode it cannot find it? How is this possible?

Any ideas?

A: 

The difference can in in the current directory, if pszListFile contains relative path.

Alex Farber
Thank you, Alex. pszListFile is a 100% absolute path, verified in the debugger as well. So this isn't it.
Android Eve
I remember that "File doesn't exist" is 2, and not 3, maybe I am wrong... What is exact pszListFile value, try to print it using OutputDebugString.
Alex Farber
The exact pszListFile value is "C:\Program Files\TestCo\TestApp\list.txt". Note the difference between ERROR_FILE_NOT_FOUND (2) and ERROR_PATH_NOT_FOUND (3).
Android Eve