Here's my code, this is a trivial test program I wrote to isolate the problem.
When I run it with debugging it throws an exception in open.c, in the function _tsopen_nolock(...), at the line
using namespace std;
The exception message is:
if ( (osfh = CreateFile( (LPTSTR)path,
== (HANDLE)(-1) )
Note that this is NOT just a "first-chance" exception from the debugger that I can ignore, even if I continue I get the same exception again, without the "first-chance" qualifier, and the file is not successfully opened and cannot be written to.
Unhandled exception at 0x7721631f in TestProject.exe: 0xC0000008: An invalid handle was specified.
After some digging around with WinDbg and searching online I found that the cause of this exception is:
... but that doesn't help me very much.
Invalid Handle exception (0xC0000008) can frequently be seen in crash dumps. It results from an invalid handle value passed to CloseHandle and other Win32 API or when a handle or return status is checked manually for validity and the same exception is raised via RaiseException or internally via RtlRaiseStatus.
Once the exception it thrown if I go to the specified location then the file HAS been created, and Windows tells me I can't delete it because "the file is open in TestProject.exe".
Finally, if I run the program using Ctrl-F5, start program without debugging, then it runs perfectly and I can write to the file.
This problem seems to just have come out of nowhere. I can't think of anything that I changed between last Friday when it was working and yesterday when it this started happening. Any ideas GREATLY appreciated.
<EDIT> I forgot to mention I'm using MS Visual C++ 2010 Express </EDIT>