CreateFile() returns INVALID_HANDLE_VALUE but GetLastError() is ERROR_SUCCESS
问题 I am opening a serial port using CreateFile(). I've got a testcase (too complicated to redistribute) that consistently causes CreateFile() to return INVALID_HANDLE_VALUE and GetLastError() to return ERROR_SUCCESS . By the looks of it, this bug only occurs if one thread opens the port at the exact same time that another port closes it. The thread opening the port runs across this problem. I don't know if this makes a difference, but later on in the code I associate the port with a