Communication between Windows drivers and Applications

Source: Internet
Author: User

Driver layer:

Pio_stack_location stack = iogetcurrentirpstacklocation (pirp );

// Obtain the input buffer size
Ulong cbin = stack-> parameters. deviceiocontrol. inputbufferlength;

// Obtain the size of the output buffer.
Ulong cbout = stack-> parameters. deviceiocontrol. outputbufferlength;
// Obtain the ioctl code
Ulong code = stack-> parameters. deviceiocontrol. iocontrolcode;

 

 

Ctl_code (Devicetype,Function,Method,Access) // Ntddk. h
Method:

Method_buffered // buffer Mode

Method_in_direct or method_out_direct // direct ing address

Method_neither

 

 

If it is method_in_direct or method_out_direct, the input and buffer modes are the same, but the output is no longer the input address,

UseMmgetsystemaddressformdlsafe in pmdlMDL,

/* IRP-> mdladdress */In mm_page_priorityPriorityNormalpagepriority); ing

 

 

IfMethod_neither:

Input address int * inputbuffer = (int *) Stack-> parameters. deviceiocontrol. type3inputbuffer;

Output address: IRQ-> userbuffer

Before the operation, you must determine: probeforreadAndThe two functions probeforwrite determine whether they can be read and written.

Last

// Process the corresponding IPR
Pirp-> iostatus. Information = Info; // you can specify 0 bytes for the returned operation.
Pirp-> iostatus. Status = STATUS_SUCCESS; // return success
Iocompleterequest (pirp, io_no_increment); // indicates that the IRP is completed.

 

 

 

 

 

User Layer

1: createfile

2: bool winapi deviceiocontrol (
_ In handleHdevice,
_ In DWORDDwiocontrolcode,
_ In lpvoidLpinbuffer,
_ In DWORDNinbuffersize,
_ Out lpvoidLpoutbuffer,
_ In DWORDNoutbuffersize,
_ Out lpdwordLpbytesreturned,
_ In lpoverlappedLpoverlapped
);

 

 

 

Http://www.hztraining.com/bbs/showtopic-484.aspx

 

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.