RE: Ntstatus in DeviceIoControl

Use ZwDeviceIoControl in user space to get the NTSTATUS, if you use
DeviceIoControl the value is translated into a Win32 error code you can
get from GetLastError if the DeviceIoControl returns zero.

Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

-----Original Message-----
From: xxxxx@gmail.com [mailto:xxxxx@gmail.com]
Posted At: Friday, May 07, 2010 2:27 PM
Posted To: ntdev
Conversation: Ntstatus in DeviceIoControl.
Subject: Ntstatus in DeviceIoControl.

Hi,

I am sending an IOCTL to my driver from a user mode program using
DeviceIoControl. In the driver I return various NTSTATUS codes in
WdfRequestComplete.

My question is how do I get the returned NTSTATUS value in the user
mode
program?

Thanks,

Kevin.

__________ Information from ESET Smart Security, version of virus
signature
database 5095 (20100507) __________

The message was checked by ESET Smart Security.

http://www.eset.com

An alternative to the custom bit trick is to use NtDeviceIoControl from
user space and get the result directly as the return value.

Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

-----Original Message-----
From: Tim Roberts [mailto:xxxxx@probo.com]
Posted At: Tuesday, May 11, 2010 7:51 PM
Posted To: ntdev
Conversation: Ntstatus in DeviceIoControl.
Subject: Re: Ntstatus in DeviceIoControl.

xxxxx@gmail.com wrote:
> 1. I am sending an IOCTL to my driver from a user mode program using
DeviceIoControl.
> 2. In the driver I return various NTSTATUS codes in
WdfRequestComplete.
> 3. In the user mode program I do:
>

In your WAIT_OBJECT_0+0 case,call GetOverlappedResult. If that
returns non-
zero, then you had STATUS_SUCCESS. If that returns zero, only then
should you
call GetLastError. That will return the NSTATUS, although it will
have gone
through the DDK -> SDK error code translation process that converts
STATUS_xxx
to the equivalent ERROR_xxx codes.

If you want to return a value unscathed, set the “custom” bit in the
NTSTATUS
value (which means in the range 0xE0000000 to 0xFFFFFFFF).


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

__________ Information from ESET Smart Security, version of virus
signature
database 5106 (20100511) __________

The message was checked by ESET Smart Security.

http://www.eset.com