PC Review


Reply
Thread Tools Rate Thread

GetSignalStrength for network wireless cards

 
 
Gianco
Guest
Posts: n/a
 
      15th Jul 2004
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
 
Reply With Quote
 
 
 
 
Chris Tacke, eMVP
Guest
Posts: n/a
 
      15th Jul 2004
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/SourceBrows.../OpenNETCF.Net

Looking in the online help I see an Adapter.StrengthFetcher:
http://www.opennetcf.org/library/Ope...terFields.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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
 
Paul G. Tobey [eMVP]
Guest
Posts: n/a
 
      15th Jul 2004
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" <(E-Mail Removed)> wrote in message
news:u8xMy$(E-Mail Removed)...
> 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/SourceBrows.../OpenNETCF.Net
>
> Looking in the online help I see an Adapter.StrengthFetcher:
> http://www.opennetcf.org/library/Ope...terFields.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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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

>
>



 
Reply With Quote
 
Gianco
Guest
Posts: n/a
 
      16th Jul 2004
Great, I solved my problem

Thanks a lot
Gianco
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Free Greeting cards, Birthday cards, Printable greeting cards,Greetings, Funny Ecards cyber Microsoft Word Document Management 0 5th Jan 2008 07:48 AM
Free Greeting cards, Birthday cards, Printable greeting cards,Greetings, Funny Ecards cyber Microsoft Word Document Management 0 5th Jan 2008 07:48 AM
Free Greeting cards, Birthday cards, Printable greeting cards,Greetings, Funny Ecards cyber Microsoft Word Document Management 0 30th Dec 2007 08:50 AM
Web sites to provide Free Greeting cards, Birthday cards, Printablegreeting cards, Greetings, Funny Ecards freefreemp4@gmail.com Printers 0 27th Dec 2007 07:14 PM
Web sites to provide Free Greeting cards, Birthday cards, Printablegreeting cards, Greetings, Funny Ecards cyber Printers 0 23rd Dec 2007 03:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:24 PM.