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:
ERR开发者_StackOverflowOR_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?
The difference can in in the current directory, if pszListFile contains relative path.
The problem did not occur again. Abandoned until further notice.
精彩评论