Trying to do asynchronous I/O on a device. My problem is ReadFile returns ERROR_INVALID_HANDLE.
I believe both Handle and OVERLAPPED hEvent are initialized so would very much appreciate it if someone could tell me what I'm doing wrong.
What I called a device is the Windows driver sample ndisprot which is a NDIS protocol driver.
What I have tried:
I have synchronous I/O and asynchronous I/O using ReadFileEx/WriteFileEx working.
This is the code I'm using:
HANDLE Handle = CreateFileA(
ndisprot630,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL
);
if (Handle == INVALID_HANDLE_VALUE)
{
DEBUGP("CreateFile failed, error 0x%x\n", GetLastError());
return(INVALID_HANDLE_VALUE);
}
OVERLAPPED ol = { 0 };
ol.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
char buf[1500];
if (!ReadFile(Handle, buf, sizeof(buf), NULL, &ol))
{
if (GetLastError() != ERROR_IO_PENDING)
{
DEBUGP("Error starting ReadFile 0x%x\n", GetLastError());
}
}