Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Before Posting... Please check out the Community Guidelines in the
Announcements and Administration Category, below.

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.

Comments

  • 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
  • OSR_Community_UserOSR_Community_User Posts: 110,218
    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
    >
  • Maxim_S._ShatskihMaxim_S._Shatskih Posts: 10,396
    > 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.
  • Scott_NooneScott_Noone Posts: 2,989
    >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" <xxxxx@storagecraft.com> 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
    >
    >
  • Gary_Little-3Gary_Little-3 Posts: 1,208
    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
  • Pavel_APavel_A Posts: 2,640
    <xxxxx@gmail.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.
  • Tim_RobertsTim_Roberts Posts: 12,567
    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.

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!