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.

Actually you didn’t.

NTSTATUS code is converted to a Win32 error code when the request finish.

Regards,

Fernando Roberto da Silva
DriverEntry Kernel Development
http://www.driverentry.com.br

You can also use the IRP Tracker to see the status of your requests.

Best Regards,

Ismael

On Fri, May 7, 2010 at 3:26 PM, wrote:

> 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.
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

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

From GetLastError after DeviceIoControl returned FALSE, or from GetOverlappedResult.

They will be converted to Win32 errors, the conversion table is described somewhere on MS’s site - google for “Mapping NTSTATUS Win32 error”.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

Thanks for the answers.

Kevin.

>They will be converted to Win32 errors, the conversion table is described

somewhere on MS’s site - google for “Mapping >NTSTATUS Win32 error”.

Winerror.exe in the WDK is pretty handy, it lets you translate between Win32
and NTSTATUS values.

-scott


Scott Noone
Consulting Associate
OSR Open Systems Resources, Inc.
http://www.osronline.com

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
>> My question is how do I get the returned NTSTATUS value in the user mode
>> program?
>
> From GetLastError after DeviceIoControl returned FALSE, or from
> GetOverlappedResult.
>
> They will be converted to Win32 errors, the conversion table is described
> somewhere on MS’s site - google for “Mapping NTSTATUS Win32 error”.
>
> –
> Maxim S. Shatskih
> Windows DDK MVP
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>

You can define your own error messages using the Message compiler (*.mc) and
adding it to your SOURCES file SOURCES section.

Gary G. Little
H (952) 223-1349
C (952) 454-4629
xxxxx@comcast.net

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@gmail.com
Sent: Friday, May 07, 2010 1:27 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] 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.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

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

The message was checked by ESET Smart Security.

http://www.eset.com

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

The message was checked by ESET Smart Security.

http://www.eset.com

wrote in message news:xxxxx@ntdev…

> 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?

Just set the “custom” bit in your status values.
GetLastError will return these values without any conversion.

Regards,
–pa

Hi,

  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:

BOOL status = DeviceIoControl(Driver, Ioctl, Buffer, BufferSize, Buffer, BufferSize, BytesRead, &Overlapped);
error = GetLastError();
if (!status) {
// if port driver returns a pending message
if (error == ERROR_IO_PENDING) {
HANDLE hEvents[2];
hEvents[0] = Overlapped.hEvent;
hEvents[1] = evtExit;
// wait for irp complete or stop process events
DWORD WaitValue = WaitForMultipleObjects(2, hEvents, FALSE, INFINITE);
switch (WaitValue) {
case WAIT_OBJECT_0 + 0:
error = GetLastError();
break;
case WAIT_OBJECT_0 + 1:
::CancelIo(Driver);
break;
case WAIT_ABANDONED_0 + 0:
break;
case WAIT_ABANDONED_0 + 1:
break;
case WAIT_TIMEOUT:
break;
case WAIT_FAILED:
break;
default:
break;
}
}
}

CloseHandle(hEvent);
}

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

Thanks,

Kevin.

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.