Fw: Returning errors from DispatchCreate() function

Yes ! With a different value, it works !!
But now, i don’t know how to handle this situation: tha application cannot
call CloseHandle() and i need to clean the driver.

Bye

Ing. Stefano Mora

----- Original Message -----
From: “Andrei Zlate-Podani”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Wednesday, April 13, 2005 12:50 PM
Subject: Re: Returning errors from DispatchCreate() function

> Stefano Mora - EOS S.r.l. wrote:
>
> >Hi everybody,
> >in the DispatchCreate() function i need to return an error code when the
> >driver cannot open the device.
> >The code is:
> >
> >NTSTATUS DispatchCreate(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp)
> >{
> > PREMSER_DEVICE_EXTENSION pDevExt = pDevObj->DeviceExtension;
> > NTSTATUS status = STATUS_SUCCESS;
> > char msg[50];
> >
> > PAGED_CODE();
> >
> > if (status==STATUS_SUCCESS)
> > status = OpenSerialPort(pDevObj,pDevExt);
> >
> > if (status==STATUS_SUCCESS)
> > status = InitSerialPort(pDevExt);
> >
> > sprintf( msg, “-> Err. status=0x%X”, status);
> > Log ( pDevExt, msg);
> >
> > pIrp->IoStatus.Information = 0;
> > pIrp->IoStatus.Status = status;
> > IoCompleteRequest(pIrp, IO_NO_INCREMENT);
> > return status;
> >}
> >
> >If it unplug the device the InitSerialPort() returns status=0x0102
(TIMEOUT)
> >but the calling application receives a good handle!
> >Must i return a different status code ?
> >How can i pass to the application an error ?
> >
> >
> STATUS_TIMEOUT is a warning.
> Any value < 0 is treated as an error code.
>
> >Thanks a lot !
> >–
> >Ing. Stefano Mora
> >email: xxxxx@eos.pr.it
> >
> >
> >—
> >Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
> >
> >You are currently subscribed to ntdev as: xxxxx@bitdefender.com
> >To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >
> >
> >
>
>
> –
> Ignorance more frequently begets confidence than does knowledge.
> — Charles Darwin
>
>
>
> –
> This message was scanned for spam and viruses by BitDefender.
> For more information please visit http://linux.bitdefender.com/
>
>

You should be cleaning up anything you need to clean up before you complete
the create IRP.

=====================
Mark Roddy

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Stefano Mora - EOS
S.r.l.
Sent: Wednesday, April 13, 2005 10:56 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Fw: Returning errors from DispatchCreate() function

Yes ! With a different value, it works !!
But now, i don’t know how to handle this situation: tha application cannot
call CloseHandle() and i need to clean the driver.

Bye

Ing. Stefano Mora

----- Original Message -----
From: “Andrei Zlate-Podani”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Wednesday, April 13, 2005 12:50 PM
Subject: Re: Returning errors from DispatchCreate() function

> Stefano Mora - EOS S.r.l. wrote:
>
> >Hi everybody,
> >in the DispatchCreate() function i need to return an error code when the
> >driver cannot open the device.
> >The code is:
> >
> >NTSTATUS DispatchCreate(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp)
> >{
> > PREMSER_DEVICE_EXTENSION pDevExt = pDevObj->DeviceExtension;
> > NTSTATUS status = STATUS_SUCCESS;
> > char msg[50];
> >
> > PAGED_CODE();
> >
> > if (status==STATUS_SUCCESS)
> > status = OpenSerialPort(pDevObj,pDevExt);
> >
> > if (status==STATUS_SUCCESS)
> > status = InitSerialPort(pDevExt);
> >
> > sprintf( msg, “-> Err. status=0x%X”, status);
> > Log ( pDevExt, msg);
> >
> > pIrp->IoStatus.Information = 0;
> > pIrp->IoStatus.Status = status;
> > IoCompleteRequest(pIrp, IO_NO_INCREMENT);
> > return status;
> >}
> >
> >If it unplug the device the InitSerialPort() returns status=0x0102
(TIMEOUT)
> >but the calling application receives a good handle!
> >Must i return a different status code ?
> >How can i pass to the application an error ?
> >
> >
> STATUS_TIMEOUT is a warning.
> Any value < 0 is treated as an error code.
>
> >Thanks a lot !
> >–
> >Ing. Stefano Mora
> >email: xxxxx@eos.pr.it
> >
> >
> >—
> >Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
> >
> >You are currently subscribed to ntdev as: xxxxx@bitdefender.com
> >To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >
> >
> >
>
>
> –
> Ignorance more frequently begets confidence than does knowledge.
> — Charles Darwin
>
>
>
> –
> This message was scanned for spam and viruses by BitDefender.
> For more information please visit http://linux.bitdefender.com/
>
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

If you unplug the device just after InitSerialPort you’d return success
to the application too. The application needs to register for PNP
notifications on that handle so it can find out when the device is going
away and clean up. And eventually it will try to do some I/O operation
that will fail and usually apps give up then too (put up and error and
close the handle).

i’m unclear what you mean when you say “application cannot call
CloseHandle()”. If it got back a valid handle (as you said it did) then
it most certainly can close it - it just might not do it right away.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
Stefano Mora - EOS S.r.l.
Sent: Wednesday, April 13, 2005 7:56 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Fw: Returning errors from DispatchCreate() function

Yes ! With a different value, it works !!
But now, i don’t know how to handle this situation: tha
application cannot call CloseHandle() and i need to clean the driver.

Bye

Ing. Stefano Mora

----- Original Message -----
From: “Andrei Zlate-Podani”
> Newsgroups: ntdev
> To: “Windows System Software Devs Interest List”
> Sent: Wednesday, April 13, 2005 12:50 PM
> Subject: Re: Returning errors from DispatchCreate() function
>
>
> > Stefano Mora - EOS S.r.l. wrote:
> >
> > >Hi everybody,
> > >in the DispatchCreate() function i need to return an error
> code when the
> > >driver cannot open the device.
> > >The code is:
> > >
> > >NTSTATUS DispatchCreate(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp)
> > >{
> > > PREMSER_DEVICE_EXTENSION pDevExt = pDevObj->DeviceExtension;
> > > NTSTATUS status = STATUS_SUCCESS;
> > > char msg[50];
> > >
> > > PAGED_CODE();
> > >
> > > if (status==STATUS_SUCCESS)
> > > status = OpenSerialPort(pDevObj,pDevExt);
> > >
> > > if (status==STATUS_SUCCESS)
> > > status = InitSerialPort(pDevExt);
> > >
> > > sprintf( msg, “-> Err. status=0x%X”, status);
> > > Log ( pDevExt, msg);
> > >
> > > pIrp->IoStatus.Information = 0;
> > > pIrp->IoStatus.Status = status;
> > > IoCompleteRequest(pIrp, IO_NO_INCREMENT);
> > > return status;
> > >}
> > >
> > >If it unplug the device the InitSerialPort() returns status=0x0102
> (TIMEOUT)
> > >but the calling application receives a good handle!
> > >Must i return a different status code ?
> > >How can i pass to the application an error ?
> > >
> > >
> > STATUS_TIMEOUT is a warning.
> > Any value < 0 is treated as an error code.
> >
> > >Thanks a lot !
> > >–
> > >Ing. Stefano Mora
> > >email: xxxxx@eos.pr.it
> > >
> > >
> > >—
> > >Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
> > >
> > >You are currently subscribed to ntdev as: xxxxx@bitdefender.com
> > >To unsubscribe send a blank email to
> xxxxx@lists.osr.com
> > >
> > >
> > >
> > >
> >
> >
> > –
> > Ignorance more frequently begets confidence than does knowledge.
> > — Charles Darwin
> >
> >
> >
> > –
> > This message was scanned for spam and viruses by BitDefender.
> > For more information please visit http://linux.bitdefender.com/
> >
> >
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@windows.microsoft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

> If it unplug the device the InitSerialPort() returns status=0x0102 (TIMEOUT)

but the calling application receives a good handle!
Must i return a different status code ?

Yes.

STATUS_IO_TIMEOUT

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com