Is there a way to verify the descriptor (file) is correct?

Is there a way to check if the descriptor in my case really returned by CreateFile?

The problem I am facing is that the correct file descriptor returned by CreateFile (this is not INVALID_HANDLE_VALUE) later causes a WriteFile error, and GetLastError claims this is due to an invalid descriptor.

+3
source share
6 answers

Since it seems that you are not setting the descriptor value to INVALID_HANDLE_VALUEafter closing it, I would do to set the reading observation point in a variable HANDLE, which will cause the debugger to break into every line that refers to the value HANDLE. You will be able to see the order in which the variable is available, including when reading a variable to pass it to CloseHandle.

See: Adding a watchpoint (violation when changing a variable)

+2
source

Checking the correctness of the handle at best is a strip.

- , ( ), , , .

, , , , .

+1

.

, HANDLE , ( , , GDI ..), Windows API GetFileInformationByHandle.

, , ReadFile WriteFile nNumberOfBytesToWrite, 0.

+1

Open-File , , - , INVALID_HANDLE. , -?

0

, , :

  • , .
  • - .

, INVALID_HANDLE_VALUE , - . - ​​- . .

(1) - , ( )

0

, , , CreateFile. IIRC, INVALID_HANDLE_VALUE , GetLastError, , .

0

Source: https://habr.com/ru/post/1783593/


All Articles