GetSignalStrength for network wireless cards

G

Gianco

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
 
P

Paul G. Tobey [eMVP]

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 said:
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 said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top