GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Jan-2008, 00:29
TriveniPrabhu TriveniPrabhu is offline
New Member
 
Join Date: Jan 2008
Posts: 10
TriveniPrabhu is on a distinguished road
Post

DeviceIoControl returns 87 error code : Invalid parameter


Hi,

I am trying to get SSID of the accesspoint my handheld is connected to using NDIS.

The code is as below::

CPP / C++ / C Code:
DWORD BytesReturned;
unsigned char SSID[20];
		   
UCHAR QueryBuffer[sizeof(NDISUIO_QUERY_OID) +	                                                            sizeof(NDIS_802_11_SSID)];
		
HANDLE g_hNdisUio= CreateFile( 
					    NDISUIO_DEVICE_NAME, 
					    GENERIC_READ | GENERIC_WRITE, 
					    FILE_SHARE_READ | FILE_SHARE_WRITE, 
					    NULL, 
				           OPEN_EXISTING, 
					    FILE_ATTRIBUTE_NORMAL |   FILE_FLAG_OVERLAPPED, 
					    INVALID_HANDLE_VALUE                         						  );

	PNDISUIO_QUERY_OID pQueryOid;
	pQueryOid = (PNDISUIO_QUERY_OID)&QueryBuffer[0];
	pQueryOid->Oid = OID_802_11_SSID;

	BOOL bSuccess = (BOOLEAN)DeviceIoControl(g_hNdisUio,
	                                       IOCTL_NDISUIO_QUERY_OID_VALUE,
	(LPVOID)&QueryBuffer[0], sizeof(QueryBuffer),
	(LPVOID)&QueryBuffer[0], sizeof(QueryBuffer),
                                      &BytesReturned, NULL);

			

			
			
			 if (bSuccess)
			 {
				
				 memcpy(bSSID, pQueryOid->Data,20);
				 CString ssid(bSSID);
				 MessageBox(ssid,NULL,MB_OK);
			 }

			 else
			 {
			   DWORD error = GetLastError();
			
			 }

But DeviceIoControl always returns 0 and GetLastError() shows the error code as 87...Invalid Parameter..I searched for this on the net, but did not find a solution. Can anybody tell me the solution for this.

Thanks
Triveni
Last edited by LuciWiz : 04-Jan-2008 at 21:40. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #2  
Old 04-Jan-2008, 22:17
TriveniPrabhu TriveniPrabhu is offline
New Member
 
Join Date: Jan 2008
Posts: 10
TriveniPrabhu is on a distinguished road

Re: DeviceIoControl returns 87 error code : Invalid parameter


Hi,

Solved the problem..

regards,
Triveni Prabhu
  #3  
Old 29-Jan-2008, 14:24
wish1267 wish1267 is offline
New Member
 
Join Date: Jan 2008
Posts: 1
wish1267 is on a distinguished road

Re: DeviceIoControl returns 87 error code : Invalid parameter


What was the solution? I am trying to do something similar but I always get Return value 0 with Error code 87. can you post your solution or source code that worked? Thank you
  #4  
Old 29-Jan-2008, 20:21
TriveniPrabhu TriveniPrabhu is offline
New Member
 
Join Date: Jan 2008
Posts: 10
TriveniPrabhu is on a distinguished road

Re: DeviceIoControl returns 87 error code : Invalid parameter


Hi,

I was getting this error because I had passed wrong parameters to DeviceIoControl.
Here is the code which worked

static bool GetSsid(LPCTSTR pszAdapter, NDIS_802_11_SSID* pSsid)
{
HANDLE hDevice = CreateFile(
NDISUIO_DEVICE_NAME, GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);

if (hDevice == INVALID_HANDLE_VALUE)
return false;

BYTE pBuffer[sizeof(NDISUIO_QUERY_OID) + sizeof(NDIS_802_11_SSID)];
PNDISUIO_QUERY_OID pNDISUIOQueryOid = (PNDISUIO_QUERY_OID) pBuffer;

pNDISUIOQueryOid->ptcDeviceName = (PTCHAR) pszAdapter;
pNDISUIOQueryOid->Oid = OID_802_11_SSID;

DWORD dwBytesReturned = 0;

if (!DeviceIoControl(
hDevice, IOCTL_NDISUIO_QUERY_OID_VALUE,
pBuffer, sizeof(pBuffer),
pBuffer, sizeof(pBuffer),
&dwBytesReturned, NULL))
{
CloseHandle(hDevice);
return false;
}

CloseHandle(hDevice);
memcpy(pSsid, pNDISUIOQueryOid->Data, sizeof(NDIS_802_11_SSID));
return true;
}

Parameter "LPCTSTR pszAdapter" can be obtained using GetAdaptersInfo().
Refer "http://geekswithblogs.net/dastblog/category/5236.aspx/rss"
Hope this helps you too. Contact me in case you need more clarifications.

Cheers,
Triveni Prabhu
 
 

Recent GIDBlogMore photos on Flickr by crystalattice

Thread Tools Search this Thread
Search this Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Smart Array problem crazy_ivan C++ Forum 5 27-Sep-2007 01:01
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 20:30
Re: Programming Techniques WaltP C Programming Language 0 09-Mar-2004 23:56

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:15.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.