Returning errors from DispatchCreate() function

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 ?

Thanks a lot !

Ing. Stefano Mora
email: xxxxx@eos.pr.it

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/

Actually you should look at the definitions for NT_ERROR, NT_SUCCESS,
NT_INFORMATION, and NT_WARNING in ntdef.h. Errors and warnings all qualify
as negative numbers if the status code is considered a signed value (which
it isn’t.) The value 0x0102 is a Success code.

=====================
Mark Roddy
Windows .NET/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Andrei
Zlate-Podani
Sent: Wednesday, April 13, 2005 6:50 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] 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@hollistech.com
To unsubscribe send a blank email to xxxxx@lists.osr.com