Re: Issue with pinvoking DeviceIoControl: switching USB function driver at run time

Tech-Archive recommends: Fix windows errors by optimizing your registry



Thanks Chris.

Sorry about that, must have commented the original one, to try out something.
But I am sending a zero in there anyways, so guess it should be harmless.

Here's the code with the correction:

[DllImport("coredll.dll", EntryPoint = "DeviceIoControl", SetLastError = true)
]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool DeviceIoControl(IntPtr hDevice,
uint
dwIoControlCode,
byte[]
lpInBuffer, // LPVOID lpInBuffer - any input data required for the IOCTL
int
nInBufferSize,
byte[]
lpOutBuffer,
int
nOutBufferSize,
ref int
lpBytesReturned,
IntPtr
lpOverlapped);

****

uint dwBytes = 0;
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
System.IntPtr getUSBfnHandle = GetUfnController();

bool ioctl_ret = DeviceIoControl(getUSBfnHandle,
IOCTL_UFN_CHANGE_CURRENT_CLIENT,

enc.GetBytes
("Mass_Storage_Class"),
enc.GetByteCount
("Mass_Storage_Class"),
null, // empty lpOutBuffer
0, // no nOutBufferSize
ref dwBytes,
IntPtr.Zero);

***

Still facing the same issue though.

Thanks,
Rohan

Chris Tacke, eMVP wrote:
This is certainly wrong:

ref ulong lpBytesReturned

that's 64-bit,and it should be 32.

Hi,

[quoted text clipped - 138 lines]
Thanks,
Rohan

--
Message posted via http://www.pocketpcjunkies.com

.



Relevant Pages