Home > Back-end >  Windows driver, put up the request, in the process of request verification results is a bit unexpect
Windows driver, put up the request, in the process of request verification results is a bit unexpect

Time:09-27

The following is a reference of sail "Windows driver development technology, a" chapter 9 complete IRP synchronous and asynchronous code in the section:


The kernel read IRP processing functions:
# pragma PAGEDCODE
NTSTATUS WDK_IRP_Read (PDEVICE_OBJECT DeviceObject points IN,
IN PIRP Irp)
{
NTSTATUS status=STATUS_SUCCESS;

//get the current stack
PIO_STACK_LOCATION stack=IoGetCurrentIrpStackLocation (Irp);
//get the device extension
PDEVICE_EXTENSION pDevExt=(PDEVICE_EXTENSION) DeviceObject - & gt; DeviceExtension;

//record current IRP into list
PIRP_ENTRY PIRP_ENTRY=(PIRP_ENTRY) ExAllocatePool (PagedPool, sizeof (IRP_ENTRY));

PIrp_Entry - & gt; PIrp=Irp;
//insert queue
InsertHeadList (pDevExt - & gt; PlinklistHead_IRP, & amp; PIrp_Entry - & gt; ListEntry);


//to the current Irp pending
IoMarkIrpPending (Irp);

Return STATUS_PENDING;
}

The application layer calls are as follows:
//the function called when the asynchronous read to complete.
VOID CALLBACK MyFileIoCompletionRoutine1 (DWORD dwErroeCode,
DWORD dwNumberOfByte,
LPOVERLAPPED LPOVERLAPPED)
{

Printf (" callback function 1: read the byte % d: \ n ", dwNumberOfByte);
NReadLen=dwNumberOfByte;

}

The Main function:

BOOL bRet=ReadFileEx (hDevice, pbuffer, ulReadLen, & amp; Overlap, MyFileIoCompletionRoutine1);
Printf (" GetLastError=% d \ n ", GetLastError ());
if (! BRet & amp; & GetLastError ()==ERROR_IO_PENDING)
{
Printf (" request 1 be hang \ n ");
}


problem (asynchronously) :
1, certain treatment function, I put up certain requests; But in the user layer calls ReadFileEx interface, the return value is TRUE; The return value is zero and GetLastError (), not the book say ERROR_IO_PENDING error code?
Seek advice;


CodePudding user response:

HANDLE hDevice=CreateFile (" \ \ \ \. \ \ MyWDMCap1SymLink ",
GENERIC_READ | GENERIC_WRITE,
0,//unshared
NULL,//no use security descriptor
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED | FILE_ATTRIBUTE_NORMAL, asynchronous operations////FILE_ATTRIBUTE_NORMAL,//device properties
NULL);


If (hDevice==INVALID_HANDLE_VALUE)
{
Printf (" drive equipment failed, open drive name: % s. Error code: % d \ n ", "MyWDMCap1SymLink", GetLastError ());
return -1;
}

Above is driven open way
  • Related