From: jerryng81 on
hi, all. I wrote a program under WM 5 using C# to achieve the AP's ssid
and rssi. i have a problem for DeviceIoControl: it always raise a
MissingMethodException. the code is below:

#region PInvoke definitions
/// <summary>
/// PInvoke version of DeviceIoControl. See MSDN documentation for
further
/// information. Note that the PInvoke version hasn't been tested
with
/// overlapped I/O.
/// </summary>
/// win ce use "coredll.dll"
[DllImport ("coredll.dll")]
private static extern bool DeviceIoControl(Handle hDevice,
IOCTL dwIoControlCode, IntPtr lpInBuffer, int nInBufferSize,
IntPtr lpOutBuffer, int nOutBufferSize, out int lpBytesReturned,
IntPtr lpOverlapped);

/// <summary>
/// PInvoke version of CreateFile. See MSDN documentation for further
/// information. The constants used and their values in this library
are
/// reported nearby parameters.
/// </summary>
[DllImport ("coredll.dll")]
private static extern Handle CreateFile(
// file name
string FileName,
// access mode GENERIC_READ = 0x80000000, GENERIC_WRITE = 0x40000000
uint DesiredAccess,
// share mode 0
uint ShareMode,
// Security Attributes NULL
uint SecurityAttributes,
// how to create OPEN_EXISTING = 3
uint CreationDisposition,
// file attributes FILE_ATTRIBUTE_NORMAL = 0x80
uint FlagsAndAttributes,
// handle to template file INVALID_HANDLE_VALUE = -1
int hTemplateFile
);

/// <summary>
/// PInvoke version of CloseHandle. It is used to close the interface
to
/// the Ndisuio file.
/// </summary>
[DllImport ("coredll.dll")]

private static extern bool CloseHandle(Handle h);

/// <summary>
/// PInvoke version of Format Message. See MSDN documentation for
further
/// information.
/// Warning! This function is imported to be used only in the
/// way GetLastErrorMessage() does!
/// </summary>
[DllImport ("Fmtmsg.dll")]
private static extern int FormatMessage(
int dwFlags,
string lpSource,
int dwMessageId,
int dwLanguageId,
System.Text.StringBuilder lpBuffer,
int nSize,
IntPtr Arguments
);


DriverHandle = CreateFile("UIO1:'",
GENERIC_READ | GENERIC_WRITE, 0, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
INVALID_HANDLE_VALUE);

int BytesReturned;
if (!DeviceIoControl(DriverHandle,
IOCTL.IOCTL_NDISUIO_BIND_WAIT,
IntPtr.Zero,
0,
IntPtr.Zero,
0,
out BytesReturned,
Handle.Zero))
{
CloseHandle(DriverHandle);
DriverHandle = Handle.Zero;
throw new WiFiException(string.Format("WiFiMan: {0}",
GetLastErrorMessage()));

}

internal enum IOCTL
{

IOCTL_NDISUIO_BIND_WAIT = ((0x12) << 16) | ((0x1 | 0x2) << 14) |
((0x204) << 2) | (0),

IOCTL_NDISUIO_QUERY_BINDING = ((0x12) << 16) | ((0x1 | 0x2) << 14) |
((0x203) << 2) | (0),

IOCTL_NDISUIO_OPEN_DEVICE = ((0x12) << 16) | ((0x1 | 0x2) << 14) |
((0x200) << 2) | (0),

IOCTL_NDISUIO_QUERY_OID_VALUE = ((0x12) << 16) | ((0x1 | 0x2) << 14)
| ((0x201) << 2) | (0),

IOCTL_NDISUIO_SET_OID_VALUE = ((0x12) << 16) | ((0x1 | 0x2) << 14) |
((0x205) << 2) | (0)
}

what's wrong for my code? appreciate any help.


CE Newbie

From: Arkady Frenkel on
IMHO better as that on some csharp group , but first you didn't check
DriverHandle before DeviceIoControl and OTOH you didn't mention what
exception return to you
Arkady

<jerryng81(a)hotmail.com> wrote in message
news:1137049566.222764.57890(a)z14g2000cwz.googlegroups.com...
> hi, all. I wrote a program under WM 5 using C# to achieve the AP's ssid
> and rssi. i have a problem for DeviceIoControl: it always raise a
> MissingMethodException. the code is below:
>
> #region PInvoke definitions
> /// <summary>
> /// PInvoke version of DeviceIoControl. See MSDN documentation for
> further
> /// information. Note that the PInvoke version hasn't been tested
> with
> /// overlapped I/O.
> /// </summary>
> /// win ce use "coredll.dll"
> [DllImport ("coredll.dll")]
> private static extern bool DeviceIoControl(Handle hDevice,
> IOCTL dwIoControlCode, IntPtr lpInBuffer, int nInBufferSize,
> IntPtr lpOutBuffer, int nOutBufferSize, out int lpBytesReturned,
> IntPtr lpOverlapped);
>
> /// <summary>
> /// PInvoke version of CreateFile. See MSDN documentation for further
> /// information. The constants used and their values in this library
> are
> /// reported nearby parameters.
> /// </summary>
> [DllImport ("coredll.dll")]
> private static extern Handle CreateFile(
> // file name
> string FileName,
> // access mode GENERIC_READ = 0x80000000, GENERIC_WRITE = 0x40000000
> uint DesiredAccess,
> // share mode 0
> uint ShareMode,
> // Security Attributes NULL
> uint SecurityAttributes,
> // how to create OPEN_EXISTING = 3
> uint CreationDisposition,
> // file attributes FILE_ATTRIBUTE_NORMAL = 0x80
> uint FlagsAndAttributes,
> // handle to template file INVALID_HANDLE_VALUE = -1
> int hTemplateFile
> );
>
> /// <summary>
> /// PInvoke version of CloseHandle. It is used to close the interface
> to
> /// the Ndisuio file.
> /// </summary>
> [DllImport ("coredll.dll")]
>
> private static extern bool CloseHandle(Handle h);
>
> /// <summary>
> /// PInvoke version of Format Message. See MSDN documentation for
> further
> /// information.
> /// Warning! This function is imported to be used only in the
> /// way GetLastErrorMessage() does!
> /// </summary>
> [DllImport ("Fmtmsg.dll")]
> private static extern int FormatMessage(
> int dwFlags,
> string lpSource,
> int dwMessageId,
> int dwLanguageId,
> System.Text.StringBuilder lpBuffer,
> int nSize,
> IntPtr Arguments
> );
>
>
> DriverHandle = CreateFile("UIO1:'",
> GENERIC_READ | GENERIC_WRITE, 0, 0,
> OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
> INVALID_HANDLE_VALUE);
>
> int BytesReturned;
> if (!DeviceIoControl(DriverHandle,
> IOCTL.IOCTL_NDISUIO_BIND_WAIT,
> IntPtr.Zero,
> 0,
> IntPtr.Zero,
> 0,
> out BytesReturned,
> Handle.Zero))
> {
> CloseHandle(DriverHandle);
> DriverHandle = Handle.Zero;
> throw new WiFiException(string.Format("WiFiMan: {0}",
> GetLastErrorMessage()));
>
> }
>
> internal enum IOCTL
> {
>
> IOCTL_NDISUIO_BIND_WAIT = ((0x12) << 16) | ((0x1 | 0x2) << 14) |
> ((0x204) << 2) | (0),
>
> IOCTL_NDISUIO_QUERY_BINDING = ((0x12) << 16) | ((0x1 | 0x2) << 14) |
> ((0x203) << 2) | (0),
>
> IOCTL_NDISUIO_OPEN_DEVICE = ((0x12) << 16) | ((0x1 | 0x2) << 14) |
> ((0x200) << 2) | (0),
>
> IOCTL_NDISUIO_QUERY_OID_VALUE = ((0x12) << 16) | ((0x1 | 0x2) << 14)
> | ((0x201) << 2) | (0),
>
> IOCTL_NDISUIO_SET_OID_VALUE = ((0x12) << 16) | ((0x1 | 0x2) << 14) |
> ((0x205) << 2) | (0)
> }
>
> what's wrong for my code? appreciate any help.
>
>
> CE Newbie
>


From: Thomas F. Divine [DDK MVP] on
Wrong forum for CE driver discussions.

Nevertheless, this prototype worked for me:

/// <summary>
/// Win32 API DeviceIoControl import for P/Invoke.
/// </summary>
/// <remarks>See Win32 API DeviceIoControl documentation.</remarks>
[ DllImport( "coredll.dll", EntryPoint="DeviceIoControl",
SetLastError=true) ]
internal static extern unsafe bool _I_DeviceIoControl(
IntPtr deviceHandle,
uint ioControlCode,
void* inBuffer,
uint inBufferSize,
void* outBuffer,
uint outBufferSize,
uint* bytesReturned,
void* Overlapped
);

I called the P/Invoke function _I_DeviceIoControl so I could wrap it in a C#
DeviceIoControl method that presented more "sane" C# parameters to the rest
of the class library.

Good luck,

Thomas F. Divine, Windows DDK MVP
http://www.pcausa.com



<jerryng81(a)hotmail.com> wrote in message
news:1137049566.222764.57890(a)z14g2000cwz.googlegroups.com...
> hi, all. I wrote a program under WM 5 using C# to achieve the AP's ssid
> and rssi. i have a problem for DeviceIoControl: it always raise a
> MissingMethodException. the code is below:
>
> #region PInvoke definitions
> /// <summary>
> /// PInvoke version of DeviceIoControl. See MSDN documentation for
> further
> /// information. Note that the PInvoke version hasn't been tested
> with
> /// overlapped I/O.
> /// </summary>
> /// win ce use "coredll.dll"
> [DllImport ("coredll.dll")]
> private static extern bool DeviceIoControl(Handle hDevice,
> IOCTL dwIoControlCode, IntPtr lpInBuffer, int nInBufferSize,
> IntPtr lpOutBuffer, int nOutBufferSize, out int lpBytesReturned,
> IntPtr lpOverlapped);
>
> /// <summary>
> /// PInvoke version of CreateFile. See MSDN documentation for further
> /// information. The constants used and their values in this library
> are
> /// reported nearby parameters.
> /// </summary>
> [DllImport ("coredll.dll")]
> private static extern Handle CreateFile(
> // file name
> string FileName,
> // access mode GENERIC_READ = 0x80000000, GENERIC_WRITE = 0x40000000
> uint DesiredAccess,
> // share mode 0
> uint ShareMode,
> // Security Attributes NULL
> uint SecurityAttributes,
> // how to create OPEN_EXISTING = 3
> uint CreationDisposition,
> // file attributes FILE_ATTRIBUTE_NORMAL = 0x80
> uint FlagsAndAttributes,
> // handle to template file INVALID_HANDLE_VALUE = -1
> int hTemplateFile
> );
>
> /// <summary>
> /// PInvoke version of CloseHandle. It is used to close the interface
> to
> /// the Ndisuio file.
> /// </summary>
> [DllImport ("coredll.dll")]
>
> private static extern bool CloseHandle(Handle h);
>
> /// <summary>
> /// PInvoke version of Format Message. See MSDN documentation for
> further
> /// information.
> /// Warning! This function is imported to be used only in the
> /// way GetLastErrorMessage() does!
> /// </summary>
> [DllImport ("Fmtmsg.dll")]
> private static extern int FormatMessage(
> int dwFlags,
> string lpSource,
> int dwMessageId,
> int dwLanguageId,
> System.Text.StringBuilder lpBuffer,
> int nSize,
> IntPtr Arguments
> );
>
>
> DriverHandle = CreateFile("UIO1:'",
> GENERIC_READ | GENERIC_WRITE, 0, 0,
> OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
> INVALID_HANDLE_VALUE);
>
> int BytesReturned;
> if (!DeviceIoControl(DriverHandle,
> IOCTL.IOCTL_NDISUIO_BIND_WAIT,
> IntPtr.Zero,
> 0,
> IntPtr.Zero,
> 0,
> out BytesReturned,
> Handle.Zero))
> {
> CloseHandle(DriverHandle);
> DriverHandle = Handle.Zero;
> throw new WiFiException(string.Format("WiFiMan: {0}",
> GetLastErrorMessage()));
>
> }
>
> internal enum IOCTL
> {
>
> IOCTL_NDISUIO_BIND_WAIT = ((0x12) << 16) | ((0x1 | 0x2) << 14) |
> ((0x204) << 2) | (0),
>
> IOCTL_NDISUIO_QUERY_BINDING = ((0x12) << 16) | ((0x1 | 0x2) << 14) |
> ((0x203) << 2) | (0),
>
> IOCTL_NDISUIO_OPEN_DEVICE = ((0x12) << 16) | ((0x1 | 0x2) << 14) |
> ((0x200) << 2) | (0),
>
> IOCTL_NDISUIO_QUERY_OID_VALUE = ((0x12) << 16) | ((0x1 | 0x2) << 14)
> | ((0x201) << 2) | (0),
>
> IOCTL_NDISUIO_SET_OID_VALUE = ((0x12) << 16) | ((0x1 | 0x2) << 14) |
> ((0x205) << 2) | (0)
> }
>
> what's wrong for my code? appreciate any help.
>
>
> CE Newbie
>