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