Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hi all,
i used File System Filter driver example which belong's to "Sergey Podobry"
and i want to send some data from driver to my application using "DeviceIoControl".
Actually i got handle to the device object in right way ,but when i call "DeviceIoControl" i got blue screen .
Here what i have done.
//g_PDeviceObject  global pointer to Device object
NTSTATUS FsFilterDispatchControl(
    __in PDEVICE_OBJECT DeviceObject,
    __in PIRP           Irp
    )
{
    PIO_STACK_LOCATION ioStack = IoGetCurrentIrpStackLocation(Irp);
    ULONG			   operation;
    NTSTATUS status=STATUS_SUCCESS;
    if(DeviceObject==g_PDeviceObject)
    {
        operation = ioStack->Parameters.DeviceIoControl.IoControlCode;
        switch (operation)
             {
                 case IOCTL_OPEN_EVENT:
                    DbgPrint("IOCTL_OPEN_EVENT \n");
                    break;
                 default:
                    status=STATUS_INVALID_DEVICE_REQUEST;
                    break;
            }
        Irp->IoStatus.Status = status;
        Irp->IoStatus.Information = 0;
        IoCompleteRequest(Irp, IO_NO_INCREMENT);
        return status;
    }
    else
    {
         return FsFilterDispatchPassThrough(DeviceObject, Irp);
    }
}


In user mode Application :

DeviceDriver = CreateFile(
                   \\\\.\\example,                  // lpFileName
                   GENERIC_READ | GENERIC_WRITE,       // dwDesiredAccess
                   FILE_SHARE_READ | FILE_SHARE_WRITE, // dwShareMode
                   NULL,                               // lpSecurityAttributes
                   OPEN_EXISTING,                      // dwCreationDistribution
                   0,                                  // dwFlagsAndAttributes
                   NULL                                // hTemplateFile
                   );



   if (DeviceDriver == INVALID_HANDLE_VALUE) {

       printf("Unable to open handle to the device driver\n");
       return 1;
   }

   //
   // Send an IOCTL to the driver to signal that the named event
   // has been created and that it can now open a handle to it
   //

   if (!DeviceIoControl(DeviceDriver,
                        IOCTL_OPEN_EVENT,
                        NULL,0,
                        NULL,0 ,
                        &bytesReturned,
                        NULL)) {

       printf("The driver failed to open the named event!\n");
       return 1;

   }

   printf("you have successfully called the device !\n");

   CloseHandle(DeviceDriver);


In Driver Entry :

RtlInitUnicodeString(&usDriverName, L"\\Device\\example");
RtlInitUnicodeString(&usDosDeviceName, L"\\DosDevices\\example");


//Create device object
NtStatus = IoCreateDevice (
                  DriverObject,
                  0,
                  &usDriverName,
                  FILE_DEVICE_UNKNOWN,
                  FILE_DEVICE_SECURE_OPEN,
                  FALSE,
                  &g_PDeviceObject
                  );

//create symbolic link 

NtStatus=IoCreateSymbolicLink(&usDosDeviceName, &usDriverName);
   if(!NT_SUCCESS(NtStatus))
   {
       return NtStatus;
   }


DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = FsFilterDispatchControl;



VOID FsFilterUnload(
    __in PDRIVER_OBJECT DriverObject
    )

{
UNICODE_STRING usDosDeviceName;
RtlInitUnicodeString(&usDosDeviceName, L"\\DosDevices\\example");
IoDeleteSymbolicLink(&usDosDeviceName);
IoDeleteDevice(g_PDeviceObject);
}


finally,what i posted is only the changes i have made on the file system filter driver .
please , help me i don't know why i got blue screen during calling "DeviceIoControl".
Posted
Updated 3-Apr-11 8:24am
v2
Comments
walterhevedeich 5-Apr-11 1:45am    
If you got this from an article in CP, better ask the author. Just comment on his article.

1 solution

please provide a crash dump analysis so we can help you solve your problem this can be done by getting a crash dump and analyzing it with win debug.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900