Hi Don adn others,
would you have some templates example of software only drivers that use
several devices?
I understand the principle, but I real need to see a proper manner to do so.
I’v been able to
create two separate device objects with two IoCreateDevice call. Each of
these call use the
same DriverObject pointer ( I guess this is correct ), a different
DeviceObject pointer and a
different device name.
Because I then have two separate device objects, obviously I’ve been able to
attach these
two devices.
I also have slightly modified the DriverUnload() function in a way I
expected it be working
but it does crash in it now…, that’s why I mostly be pleased to see a
“template” made by
some experienced people around!
for reference here is my “Idiotic” DriverUnload fnc(), btw don’t be suprised
about the way I do
accessing the DeviceExtension structure, I was searching pointer in softice,
hehe!
(btw, gdrv1DeviceObject + gdrv2DeviceObject are two global pointers that are
assigned
in the DriverEntry() function ) :
VOID testUnload(
IN PDRIVER_OBJECT DriverObject
)
{
UNICODE_STRING win32Name;
HANDLE *tmpD1 = NULL, *tmpD2 = NULL;
PDEVICE_OBJECT tmpDevice1 = NULL, tmpDevice2 = NULL;
RtlInitUnicodeString(&win32Name, L"\??\testDevice");
IoDeleteSymbolicLink(&win32Name);
tmpD1 = gdrv1DeviceObject->DeviceExtension;
tmpD1 += 6;
tmpDevice1 = *tmpD1;
tmpD2 = gdrv2DeviceObject->DeviceExtension;
tmpD2 += 6;
tmpDevice2 = *tmpD2;
if(tmpDevice1!=0)
{
IoDetachDevice(tmpDevice1);
}
if(tmpDevice2!=0)
{
IoDetachDevice(tmpDevice2);
}
tmpD1 += 1;
tmpDevice1 = *tmpD1;
ObDereferenceObject(tmpDevice1);
tmpD2 += 1;
tmpDevice2 = *tmpD2;
ObDereferenceObject(tmpDevice2);
IoUnregisterShutdownNotification(DriverObject->DeviceObject);
IoDeleteDevice(DriverObject->DeviceObject);
// release memory block allocated for registry path
if (g_Data.RegistryPath.Buffer != NULL)
{
ExFreePool(g_Data.RegistryPath.Buffer);
g_Data.RegistryPath.Buffer = NULL;
}
return;
}
“Don Burn” a écrit dans le message de news:xxxxx@ntdev…
> You need to create a seperate device object for each device you are
> attaching to. The crash is because you are trying to put the device
object
> in two stacks, this can’t be done.
>
> Even if you could do this you do not want to. When a request comes into
> your driver, it will have the device object you attached as part of the
> request, if you had the same object attached to both you wouldn’t know
which
> to send it to. For your model where you want a request to routed to N
> different devices, consider creating N+1 device objects. Create one for
> each device you attach to, and then create another for the router
function.
>
>
> –
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> Remove StopSpam from the email to reply
>
> “Arnaud Maye” wrote in message news:xxxxx@ntdev…
> > Hi Doron, Tony and others
> >
> > here is some code snippets ( cleaned a bit about the msg don’t get too
> > indigest )
> >
> >
> > status = IoCreateDevice( … , … , … , … , … , … ,
> &deviceObject);
> >
> > …
> >
> > RtlInitUnicodeString(&drv1up, DRV1_DEVICE_NAME);
> > status = IoGetDeviceObjectPointer(&drv1up, 1, &drv1fObject,
> &drv1tDevice);
> > drv1fdObject = IoAttachDeviceToDeviceStack(deviceObject, drv1tDevice);
> >
> > …
> >
> > RtlInitUnicodeString(&drv2up, DRV2_DEVICE_NAME);
> > status = IoGetDeviceObjectPointer(&drv2up, 1, &drv2fObject,
&drv2tDevice);
> > drv2fdObject = IoAttachDeviceToDeviceStack(deviceObject, drv2tDevice);
> >
> >
> > then yes, I do use the same deviceObject for both “devices” I would like
> to
> > attach to.
> > I don’t know much about the bug check, but only thing I can say is that
if
> I
> > do comment
> > the latest IoAttachDeviceToDeviceStack() call system don’t crash.
> >
> > Also I am new in the driver world. I am actualy exercising a bit. Maybe
I
> am
> > doing something obviously wrong
> >
> > Best Regards
> >
> > Arnaud Maye
>
>
>