A small example of Windows Kernel Programming

Source: Internet
Author: User

# Include "ntddk. H"

Void example1unload (in pdriver_object pdrvobj)
{
Unicode_string usdosdevname;
Dbuplint ("example1: Driver is being unload. \ n ");

Rtlinitunicodestring (& usdosdevname, l "\ dosdevices \ examplelink2 ");
Iodeletesymboliclink (& usdosdevname );
Iodeletedevice (pdrvobj-> deviceobject );
}

Ntstatus exampleirp (in pdevice_object device, in pirp)
{

Dbuplint ("an driver routine is called. \ n ");
Return STATUS_SUCCESS;
}

Ntstatus DriverEntry (in pdriver_object pdrvobj, in punicode_string pusregpath)
{
Ntstatus status = status_unsuccessful;
Unicode_string usdevname;
Unicode_string usdosdevname;
Pdevice_object p1_bj = NULL;
Unsigned int nindex;
Dbuplint ("Example: Driver entry is called. \ n ");

Rtlinitunicodestring (& usdevname, l "\ device \ example3 ");
Rtlinitunicodestring (& usdosdevname, l "\ dosdevices \ examplelink2 ");

// Create Device
Status = iocreatedevice (pdrvobj, 0, & usdevname, file_device_unknown,
File_device_secure_open, false, & p1_bj );

If (nt_success (Status ))
{
For (nindex = 0; nindex <irp_mj_maximum_function; ++ nindex)
Pdrvobj-> majorfunction [nindex] = exampleirp;

Pdrvobj-> driverunload = example1unload;

// Save the created device; otherwise, it cannot be referenced later
Pdrvobj-> deviceobject = p1_bj;
Status = iocreatesymboliclink (& usdosdevname, & usdevname );
If (! Nt_success (Status ))
{
Dbuplint ("iocreatesymboliclink failed. \ n ");
Iodeletedevice (p1_bj );

}
Else
{
Dbuplint ("successed !. \ N ");
}

}
Else
{
Dbuplint ("iocreatedevice failed \ n ");
}

Return status;

}

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.