deviceiocontrol returns error 1

I am using an out of the box Umdf driver, testapp.c as for the code and the osrusbfx2 board for the c# host interface. The device is recognized and I get a valid path and get the handle in file create. I get an error code 1, Invalid function when I execute FileIO.DeviceIoControl

Import the dll methods:
[DllImport(“kernel32.dll”, SetLastError = true, CharSet = CharSet.Auto)]
internal static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);
[DllImport(“kernel32.dll”, ExactSpelling = true, SetLastError = true, CharSet = CharSet.Auto)]
internal static extern bool DeviceIoControl(IntPtr hDevice, uint dwIoControlCode,IntPtr lpInBuffer, uint nInBufferSize,IntPtr lpOutBuffer, uint nOutBufferSize,out uint lpBytesReturned, IntPtr lpOverlapped);

The actual calls:
IntPtr pDeviceHandle = FileIO.CreateFile
(myDevInfo.myDevicePathName,
(FileIO.GENERIC_WRITE | FileIO.GENERIC_READ),
FileIO.FILE_SHARE_READ | FileIO.FILE_SHARE_WRITE,
IntPtr.Zero,
FileIO.OPEN_EXISTING,
FileIO.FILE_ATTRIBUTE_NORMAL | FileIO.FILE_FLAG_OVERLAPPED,
IntPtr.Zero);

// IOCTL_OSRUSBFX2_GET_CONFIG_DESCRIPTOR
success = FileIO.DeviceIoControl
(pDeviceHandle,
CTL_CODE(0x65500, 0x800, 0, 0X80000000),
pBuffer,
size,
pBuffer,
size,
out nBytes,
IntPtr.Zero);

What am I doing wrong?

Did you define CTL_CODE somewhere? How are you pinning the buffers?

d

dent from a phpne with no keynoard

-----Original Message-----
From: xxxxx@mpr.com
Sent: November 30, 2010 6:13 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] deviceiocontrol returns error 1

I am using an out of the box Umdf driver, testapp.c as for the code and the osrusbfx2 board for the c# host interface. The device is recognized and I get a valid path and get the handle in file create. I get an error code 1, Invalid function when I execute FileIO.DeviceIoControl

Import the dll methods:
[DllImport(“kernel32.dll”, SetLastError = true, CharSet = CharSet.Auto)]
internal static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);
[DllImport(“kernel32.dll”, ExactSpelling = true, SetLastError = true, CharSet = CharSet.Auto)]
internal static extern bool DeviceIoControl(IntPtr hDevice, uint dwIoControlCode,IntPtr lpInBuffer, uint nInBufferSize,IntPtr lpOutBuffer, uint nOutBufferSize,out uint lpBytesReturned, IntPtr lpOverlapped);

The actual calls:
IntPtr pDeviceHandle = FileIO.CreateFile
(myDevInfo.myDevicePathName,
(FileIO.GENERIC_WRITE | FileIO.GENERIC_READ),
FileIO.FILE_SHARE_READ | FileIO.FILE_SHARE_WRITE,
IntPtr.Zero,
FileIO.OPEN_EXISTING,
FileIO.FILE_ATTRIBUTE_NORMAL | FileIO.FILE_FLAG_OVERLAPPED,
IntPtr.Zero);

// IOCTL_OSRUSBFX2_GET_CONFIG_DESCRIPTOR
success = FileIO.DeviceIoControl
(pDeviceHandle,
CTL_CODE(0x65500, 0x800, 0, 0X80000000),
pBuffer,
size,
pBuffer,
size,
out nBytes,
IntPtr.Zero);

What am I doing wrong?


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

Most likely your IOCTL’s Access parameter (see CTL_CODE macro and
IOCTL_OSRUSBFX2_GET_CONFIG_DESCRIPTOR definition) has invalid value.
In your code you specify 0x80000000 which is definitely not the same
as FILE_READ_ACCESS value defined as 1.
Btw. you should share declarations of common data structures or
defined constants between app and drv whenever is possible to avoid
such mistakes.

Kris

On Wed, Dec 1, 2010 at 3:11 AM, wrote:
> I am using an out of the box Umdf driver, testapp.c as for the code and the osrusbfx2 board for the c# host interface. ?The device is recognized and I get a valid path and get the handle in file create. ? I get an error code 1, Invalid function when I execute FileIO.DeviceIoControl
>
>
> Import the dll methods:
> [DllImport(“kernel32.dll”, SetLastError = true, CharSet = CharSet.Auto)]
> ? ? ? ?internal static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);
> ? ? ? ?[DllImport(“kernel32.dll”, ExactSpelling = true, SetLastError = true, CharSet = CharSet.Auto)]
> ? ? ? ?internal static extern bool DeviceIoControl(IntPtr hDevice, uint dwIoControlCode,IntPtr lpInBuffer, uint nInBufferSize,IntPtr lpOutBuffer, uint nOutBufferSize,out uint lpBytesReturned, IntPtr lpOverlapped);
>
> The actual calls:
> IntPtr pDeviceHandle = FileIO.CreateFile
> ? ? ? ? ? ? ? ? ? ? ? ?(myDevInfo.myDevicePathName,
> ? ? ? ? ? ? ? ? ? ? ? ?(FileIO.GENERIC_WRITE | FileIO.GENERIC_READ),
> ? ? ? ? ? ? ? ? ? ? ? ?FileIO.FILE_SHARE_READ | FileIO.FILE_SHARE_WRITE,
> ? ? ? ? ? ? ? ? ? ? ? ?IntPtr.Zero,
> ? ? ? ? ? ? ? ? ? ? ? ?FileIO.OPEN_EXISTING,
> ? ? ? ? ? ? ? ? ? ? ? ?FileIO.FILE_ATTRIBUTE_NORMAL | FileIO.FILE_FLAG_OVERLAPPED,
> ? ? ? ? ? ? ? ? ? ? ? ?IntPtr.Zero);
>
> ? ? ? ? ? ? ? ? ? ?// IOCTL_OSRUSBFX2_GET_CONFIG_DESCRIPTOR
> ? ? ? ? ? ? ? ? ? ?success = FileIO.DeviceIoControl
> ? ? ? ? ? ? ? ? ? ? ? ?(pDeviceHandle,
> ? ? ? ? ? ? ? ? ? ? ? ?CTL_CODE(0x65500, 0x800, 0, 0X80000000),
> ? ? ? ? ? ? ? ? ? ? ? ?pBuffer,
> ? ? ? ? ? ? ? ? ? ? ? ?size,
> ? ? ? ? ? ? ? ? ? ? ? ?pBuffer,
> ? ? ? ? ? ? ? ? ? ? ? ?size,
> ? ? ? ? ? ? ? ? ? ? ? ?out nBytes,
> ? ? ? ? ? ? ? ? ? ? ? ?IntPtr.Zero);
>
> What am I doing wrong?
>
> —
> 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
>

I don’t know where I got the 0x80000000 and it was a very long day, but I changed the FILE_READ_ACCESS value to 1, and I got 39 bytes of data!!! And I will share declarations!!!

My hats off to you as the best there is!!!

xxxxx@mpr.com wrote:

I am using an out of the box Umdf driver, testapp.c as for the code and the osrusbfx2 board for the c# host interface. The device is recognized and I get a valid path and get the handle in file create. I get an error code 1, Invalid function when I execute FileIO.DeviceIoControl

The actual calls:
IntPtr pDeviceHandle = FileIO.CreateFile
(myDevInfo.myDevicePathName,
(FileIO.GENERIC_WRITE | FileIO.GENERIC_READ),
FileIO.FILE_SHARE_READ | FileIO.FILE_SHARE_WRITE,
IntPtr.Zero,
FileIO.OPEN_EXISTING,
FileIO.FILE_ATTRIBUTE_NORMAL | FileIO.FILE_FLAG_OVERLAPPED,
IntPtr.Zero);

// IOCTL_OSRUSBFX2_GET_CONFIG_DESCRIPTOR
success = FileIO.DeviceIoControl
(pDeviceHandle,
CTL_CODE(0x65500, 0x800, 0, 0X80000000),
pBuffer,
size,
pBuffer,
size,
out nBytes,
IntPtr.Zero);

What am I doing wrong?

For one thing, you opened the file with FILE_FLAG_OVERLAPPED, but you
did not supply an OVERLAPPED structure in the DeviceIoControl call.
When you open a file in overlapped mode, EVERY I/O request must be done
with an OVERLAPPED structure. It doesn’t crash (at least not every
time), but that violates the contract.


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