Read and write operation of Windows Driver Development technology detailed

Source: Internet
Author: User

    • Buffer mode read and write operations

Read and write operations are generally caused by readfile and WriteFile functions, where the WriteFile function is the first example to be introduced. WriteFile requires the user to provide a buffer and describes the size of the buffer, and then writefile the memory data into the driver. In this way, the operating system copies the application-supplied buffer data directly into the kernel-mode address . This makes it easier to solve the problem of passing the user address into the driver, but the disadvantage is that it is necessary to replicate the data between user mode and kernel mode, which affects the efficiency. This method can be used in a small amount of memory operations. Copy the AssociatedIrp.SystemBuffer subdomain record of the IRP created by WriteFile to the address in kernel mode.

The following code shows how to read a device using a buffer, in which case the driver is responsible for filling in the data into the buffer:

The application layer calls ReadFile and wants to drive a read IRP request:

1 intMain () {2HANDLE Hdevice =3CreateFile ("\\\\.\\HELLODDK",4Generic_read |Generic_write,5             0, NULL,6 open_existing,7 File_attribute_normal,8 NULL);9         if(Hdevice = =Invalid_handle_value) {Tenprintf"Open Device failed!\n"); One         } A         Else{ -printf"Open Device succeed!\n"); -         } theUCHAR buffer[Ten]; - ULONG Ulread; -BOOL BRet = ReadFile (hdevice, buffer,Ten, &Ulread, NULL); -         if(bRet) { +printf"Read%d bytes!", ulread); -              for(inti =0; I < (int) Ulread; i++){ +printf"%02x", Buffer[i]); A             } atprintf"\ n"); -         } - CloseHandle (hdevice); -System"Pause"); -         return 0; -}

The results after the run are as follows:

Read and write operation of Windows Driver Development technology detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.