> std::cout << "## problem : " << GetLastError() << std::endl;
That won't work as GetLastError() might be called after std::cout does
I/O and changes its value. (The invalid handle error you saw is a typical
phantom error status.) To get a meaningful error code you need to do
DWORD err = GetLastError();
std::cout << "## problem : " << err << std::endl;
printf("## problem : %ld\n", GetLastError());
As for your actual problem, it's the sort of thing I'd use Sysinternals'
Process Monitor (procmon) to figure out what's going on.