I want to read some data from a device connected to a COM port.
-
HANDLE handle =CreateFileW(L"\\\\.\\COM3", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);gives me a valid
HANDLEwhich is then configured viaGetCommStateandSetCommState. -
OVERLAPPED ol = {0};char buffer[1024];ol.Offset = 0;ol.OffsetHigh = 0;ReadFileEx(handle, buffer, 1, &ol, NULL);The problem is, that this call doesn’t succeed and
GetLastError()returns 87 (ERROR_INVALID_PARAMETER).
What could I try to be able to read from the device?
The ReadFileEx documentation states that
So although it also says that the completion routine is optional, it’s probably needed. Also note the community comment at the bottom of the page you linked to – MS may have fixed that crash by considering a NULL lpCompletionRoutine an error. However, I have not tested it to verify.
If you are not using a completion routine you can use the normal ReadFile for your overlapped operation.