I am working on WIN CE platform, developing windows forms in C#.Net. Successfully created handle for NDISUIO ("UIO1:").
Check the API:
string AUB_NAME = "PCI\\ManiXX1";
byte[] toBytes = Encoding.ASCII.GetBytes(AUB_NAME);
int IOCTL_NDIS_QUERY = new int();
IOCTL_NDIS_QUERY = IOCTL_NDISUIO_OPEN_DEVICE;
IoctlResult = DeviceIoControl(
hFileHandle,
IOCTL_NDIS_QUERY,
toBytes,
(int)(11 * sizeof(UInt16)),//It should be 11 or 22 bytes?
null,
0,
ref dwReturnedBytes,
0);
The above syntax is corresponding to the first prototype as mentioned below.
Prototype for the Above API:
//deviceIoControl - overloaded
[DllImport("coredll.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool DeviceIoControl(int hDevice, int dwIoControlCode,
byte[] InBuffer, int nInBufferSize,
byte[] OutBuffer, int nOutputBufferSize,
ref int pBytesReturned, int pOverlapped);
When I run this code in WIN CE machine I am getting the error code 87, (The parameter is incorrect.ERROR_INVALID_PARAMETER)
I am checking the parameters, I feel those are correct, can anybody tell me regarding the parameters info and its type, which prototype should be followed for deviceiocontrol API in C#.net Compact framework?
A bit late to the party here, but two other things to be aware of with
IOCTL_NDISUIO_OPEN_DEVICE
:DeviceIoControl
must not beconst
, or the call will fail with error 87 (ERROR_INVALID_PARAMETER
) as NDISUIO attempts to copy data back into the input buffer(!) So don't pass a string literal the way some MSDN samples do.ERROR_GEN_FAILURE
). MSDN does point out that the NULL character should be disregarded, but the wording makes it sound optional when in reality it isn't.This looks wrong to me:
Windows CE is very, very heavily biased toward Unicode. It should probably be: