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?