GetSignalStrength for network wireless cards

Discussion in 'Microsoft Dot NET Compact Framework' started by Gianco, Jul 15, 2004.

  1. Gianco

    Gianco Guest

    Hello people

    I found the following C++ source code posted by Paul Tobey to obtain
    the strength of a network wireless signal:

    extern "C" __declspec(dllexport) INT GetSignalStrength(TCHAR
    *ptcDeviceName, INT *piSignalStrength)
    {
    PNDISUIO_QUERY_OID queryOID;
    DWORD dwBytesReturned = 0;
    UCHAR QueryBuffer[sizeof(NDISUIO_QUERY_OID)+sizeof(DWORD)];
    HANDLE ndisAccess = INVALID_HANDLE_VALUE;
    BOOL retval;
    INT hr;

    // Attach to NDISUIO.
    ndisAccess = CreateFile(NDISUIO_DEVICE_NAME, 0, 0, NULL,
    OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
    INVALID_HANDLE_VALUE );

    if (ndisAccess == INVALID_HANDLE_VALUE) return -1;

    // Get Signal strength
    queryOID = (PNDISUIO_QUERY_OID)&QueryBuffer[0];
    queryOID->ptcDeviceName = ptcDeviceName;
    queryOID->Oid = OID_802_11_RSSI;

    retval = DeviceIoControl(ndisAccess,
    IOCTL_NDISUIO_QUERY_OID_VALUE, (LPVOID)queryOID,
    sizeof(NDISUIO_QUERY_OID) + sizeof(DWORD), (LPVOID)queryOID,
    sizeof(NDISUIO_QUERY_OID) + sizeof(DWORD), &dwBytesReturned, NULL);

    if (retval && piSignalStrength)
    {
    hr = 0;
    *piSignalStrength = *(DWORD *)&queryOID->Data;
    }
    else
    {
    hr = -2;
    }

    CloseHandle(ndisAccess);

    return(hr);
    }

    So I created a DLL with eVC 4 changing a little bit the function so it
    returns an integer value that indicate the success or the error code
    (-1 if the CreateFile call fails, -2 if the DeviceIoControl call
    fails)

    I use it in C# declared in this way:
    [DllImport("mydll.dll")]
    private static extern int GetSignalStrength(string sDeviceName, ref
    Int32 iStrength)

    It returns -2, I would understand why...

    Could it be that I declared it in a wrong way? The sDeviceName must be
    not declared as "string" because in the DLL is a TCHAR pointer?

    The device name is wrong? I pass to the function the name "PRISMNDS1"
    that I find in the menu \START\SETTINGS\NETWORK AND DIAL-UP
    CONNECTIONS, is it correct?

    The OS is Windows CE .NET 4.1 V1.20 - is the GetSignalStrength
    compatible with it? If not, have I the chance to modify the function
    to make it compatible with my OS?

    Thanks in advance to all
    Gianco
     
    Gianco, Jul 15, 2004
    #1
    1. Advertisements

  2. SignalStrength is part of the OpenNETCF.Net namespace, so I can only assume
    that either the Adapter or AccessPoint class exposes it.

    http://www.opennetcf.org/SourceBrow...penNETCF/InetPub/wwwroot/Source/OpenNETCF.Net

    Looking in the online help I see an Adapter.StrengthFetcher:
    http://www.opennetcf.org/library/OpenNETCF.Net.AdapterFields.html

    That seems like a good start.


    --
    Chris Tacke, eMVP
    Co-Founder and Advisory Board Member
    www.OpenNETCF.org
    ---
    ---
    Principal Partner
    OpenNETCF Consulting
    www.OpenNETCF.com



    "Gianco" <> wrote in message
    news:...
    > Hello people
    >
    > I found the following C++ source code posted by Paul Tobey to obtain
    > the strength of a network wireless signal:
    >
    > extern "C" __declspec(dllexport) INT GetSignalStrength(TCHAR
    > *ptcDeviceName, INT *piSignalStrength)
    > {
    > PNDISUIO_QUERY_OID queryOID;
    > DWORD dwBytesReturned = 0;
    > UCHAR QueryBuffer[sizeof(NDISUIO_QUERY_OID)+sizeof(DWORD)];
    > HANDLE ndisAccess = INVALID_HANDLE_VALUE;
    > BOOL retval;
    > INT hr;
    >
    > // Attach to NDISUIO.
    > ndisAccess = CreateFile(NDISUIO_DEVICE_NAME, 0, 0, NULL,
    > OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
    > INVALID_HANDLE_VALUE );
    >
    > if (ndisAccess == INVALID_HANDLE_VALUE) return -1;
    >
    > // Get Signal strength
    > queryOID = (PNDISUIO_QUERY_OID)&QueryBuffer[0];
    > queryOID->ptcDeviceName = ptcDeviceName;
    > queryOID->Oid = OID_802_11_RSSI;
    >
    > retval = DeviceIoControl(ndisAccess,
    > IOCTL_NDISUIO_QUERY_OID_VALUE, (LPVOID)queryOID,
    > sizeof(NDISUIO_QUERY_OID) + sizeof(DWORD), (LPVOID)queryOID,
    > sizeof(NDISUIO_QUERY_OID) + sizeof(DWORD), &dwBytesReturned, NULL);
    >
    > if (retval && piSignalStrength)
    > {
    > hr = 0;
    > *piSignalStrength = *(DWORD *)&queryOID->Data;
    > }
    > else
    > {
    > hr = -2;
    > }
    >
    > CloseHandle(ndisAccess);
    >
    > return(hr);
    > }
    >
    > So I created a DLL with eVC 4 changing a little bit the function so it
    > returns an integer value that indicate the success or the error code
    > (-1 if the CreateFile call fails, -2 if the DeviceIoControl call
    > fails)
    >
    > I use it in C# declared in this way:
    > [DllImport("mydll.dll")]
    > private static extern int GetSignalStrength(string sDeviceName, ref
    > Int32 iStrength)
    >
    > It returns -2, I would understand why...
    >
    > Could it be that I declared it in a wrong way? The sDeviceName must be
    > not declared as "string" because in the DLL is a TCHAR pointer?
    >
    > The device name is wrong? I pass to the function the name "PRISMNDS1"
    > that I find in the menu \START\SETTINGS\NETWORK AND DIAL-UP
    > CONNECTIONS, is it correct?
    >
    > The OS is Windows CE .NET 4.1 V1.20 - is the GetSignalStrength
    > compatible with it? If not, have I the chance to modify the function
    > to make it compatible with my OS?
    >
    > Thanks in advance to all
    > Gianco
     
    Chris Tacke, eMVP, Jul 15, 2004
    #2
    1. Advertisements

  3. They both, in the next version, at least, expose a signal strength. In the
    case of the one from the adapter, that indicates the strength of the actual
    associated connection to a particular access point. In the case of the
    access point class, the strength indicates how strong the signal from that
    access point is, whether the card is currently associated with the access
    point or not. So, which one you use depends on what you care about.

    Paul T.

    "Chris Tacke, eMVP" <> wrote in message
    news:u8xMy$...
    > SignalStrength is part of the OpenNETCF.Net namespace, so I can only

    assume
    > that either the Adapter or AccessPoint class exposes it.
    >
    >

    http://www.opennetcf.org/SourceBrow...penNETCF/InetPub/wwwroot/Source/OpenNETCF.Net
    >
    > Looking in the online help I see an Adapter.StrengthFetcher:
    > http://www.opennetcf.org/library/OpenNETCF.Net.AdapterFields.html
    >
    > That seems like a good start.
    >
    >
    > --
    > Chris Tacke, eMVP
    > Co-Founder and Advisory Board Member
    > www.OpenNETCF.org
    > ---
    > ---
    > Principal Partner
    > OpenNETCF Consulting
    > www.OpenNETCF.com
    >
    >
    >
    > "Gianco" <> wrote in message
    > news:...
    > > Hello people
    > >
    > > I found the following C++ source code posted by Paul Tobey to obtain
    > > the strength of a network wireless signal:
    > >
    > > extern "C" __declspec(dllexport) INT GetSignalStrength(TCHAR
    > > *ptcDeviceName, INT *piSignalStrength)
    > > {
    > > PNDISUIO_QUERY_OID queryOID;
    > > DWORD dwBytesReturned = 0;
    > > UCHAR QueryBuffer[sizeof(NDISUIO_QUERY_OID)+sizeof(DWORD)];
    > > HANDLE ndisAccess = INVALID_HANDLE_VALUE;
    > > BOOL retval;
    > > INT hr;
    > >
    > > // Attach to NDISUIO.
    > > ndisAccess = CreateFile(NDISUIO_DEVICE_NAME, 0, 0, NULL,
    > > OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
    > > INVALID_HANDLE_VALUE );
    > >
    > > if (ndisAccess == INVALID_HANDLE_VALUE) return -1;
    > >
    > > // Get Signal strength
    > > queryOID = (PNDISUIO_QUERY_OID)&QueryBuffer[0];
    > > queryOID->ptcDeviceName = ptcDeviceName;
    > > queryOID->Oid = OID_802_11_RSSI;
    > >
    > > retval = DeviceIoControl(ndisAccess,
    > > IOCTL_NDISUIO_QUERY_OID_VALUE, (LPVOID)queryOID,
    > > sizeof(NDISUIO_QUERY_OID) + sizeof(DWORD), (LPVOID)queryOID,
    > > sizeof(NDISUIO_QUERY_OID) + sizeof(DWORD), &dwBytesReturned, NULL);
    > >
    > > if (retval && piSignalStrength)
    > > {
    > > hr = 0;
    > > *piSignalStrength = *(DWORD *)&queryOID->Data;
    > > }
    > > else
    > > {
    > > hr = -2;
    > > }
    > >
    > > CloseHandle(ndisAccess);
    > >
    > > return(hr);
    > > }
    > >
    > > So I created a DLL with eVC 4 changing a little bit the function so it
    > > returns an integer value that indicate the success or the error code
    > > (-1 if the CreateFile call fails, -2 if the DeviceIoControl call
    > > fails)
    > >
    > > I use it in C# declared in this way:
    > > [DllImport("mydll.dll")]
    > > private static extern int GetSignalStrength(string sDeviceName, ref
    > > Int32 iStrength)
    > >
    > > It returns -2, I would understand why...
    > >
    > > Could it be that I declared it in a wrong way? The sDeviceName must be
    > > not declared as "string" because in the DLL is a TCHAR pointer?
    > >
    > > The device name is wrong? I pass to the function the name "PRISMNDS1"
    > > that I find in the menu \START\SETTINGS\NETWORK AND DIAL-UP
    > > CONNECTIONS, is it correct?
    > >
    > > The OS is Windows CE .NET 4.1 V1.20 - is the GetSignalStrength
    > > compatible with it? If not, have I the chance to modify the function
    > > to make it compatible with my OS?
    > >
    > > Thanks in advance to all
    > > Gianco

    >
    >
     
    Paul G. Tobey [eMVP], Jul 15, 2004
    #3
  4. Gianco

    Gianco Guest

    Great, I solved my problem

    Thanks a lot
    Gianco
     
    Gianco, Jul 16, 2004
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lloyd Dupont

    [Interop] how to check wireless network test ?

    Lloyd Dupont, Oct 26, 2003, in forum: Microsoft Dot NET Compact Framework
    Replies:
    2
    Views:
    230
    Lloyd Dupont
    Oct 27, 2003
  2. Franky

    test wireless network connection

    Franky, Jan 28, 2004, in forum: Microsoft Dot NET Compact Framework
    Replies:
    0
    Views:
    221
    Franky
    Jan 28, 2004
  3. Tomppa

    Configure wireless network connection programmatically?

    Tomppa, Jan 31, 2006, in forum: Microsoft Dot NET Compact Framework
    Replies:
    8
    Views:
    3,980
    Paul G. Tobey [eMVP]
    Jan 31, 2006
  4. Peter Huish

    Wireless network selection

    Peter Huish, Mar 28, 2007, in forum: Microsoft Dot NET Compact Framework
    Replies:
    4
    Views:
    244
    Guest
    May 14, 2007
  5. Sagaert Johan

    Debugging via (wireless) network

    Sagaert Johan, Apr 13, 2007, in forum: Microsoft Dot NET Compact Framework
    Replies:
    2
    Views:
    194
    Guest
    Apr 13, 2007
Loading...

Share This Page