# 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;
}