Click here to Skip to main content
12,397,805 members (50,336 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VC7 C++
i have put condition like when it found adhoc it should connect with that
my friend has created adhoc with no authentication and when i am running this code it is giving me error like invalid parameter so please help me out..
first of all i am scanning all available network which give result in pAvailableNetworkList object which is i am accessing over here..

if(pAvailableNetworkList->Network[i].dot11BssType==2)
{
 cout<<"\nProcess to Connect to adhoc";
 WLAN_CONNECTION_PARAMETERS ConnPara;
 ConnPara.wlanConnectionMode = wlan_connection_mode_discovery_unsecure;
 ConnPara.strProfile = NULL;
 
 DOT11_SSID temp2;
temp2.uSSIDLength = pAvailableNetworkList->Network             [i].dot11Ssid.uSSIDLength;
temp2.ucSSID[temp2.uSSIDLength] = pAvailableNetworkList->Network [i].dot11Ssid.ucSSID[temp2.uSSIDLength];
			
 ConnPara.pDot11Ssid = &temp2;
 ConnPara.pDesiredBssidList =NULL;
 ConnPara.dot11BssType = dot11_BSS_type_any;
 ConnPara.dwFlags = WLAN_CONNECTION_ADHOC_JOIN_ONLY;
 DWORD temp =WlanConnect(
                  hClientHandle,
		  &interfaceGuid,
		  &ConnPara,
		  NULL
			);
if(temp == ERROR_SUCCESS)
  cout<<"\nSuccess";
if(temp == ERROR_INVALID_PARAMETER)
  cout<<"\nERROR INVALID PARAMETER";  ///I am getting this error
}
Posted 22-Feb-10 0:31am
Updated 22-Feb-10 0:59am
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try ASSERT(hClientHanle); at debugging... Smile | :)
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

OSVERSIONINFO osvi;
memset(&osvi, 0, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

LPWSTR pProfileXml = NULL;
DWORD dwFlags = 0;
DOT11_BSSID_LIST DesiredBssidList ;
WLAN_CONNECTION_PARAMETERS *wlanParam=(WLAN_CONNECTION_PARAMETERS*)WlanAllocateMemory(sizeof(WLAN_CONNECTION_PARAMETERS));


GetVersionEx(&osvi);
if (osvi.dwMajorVersion >= 6){
WLAN_BSS_LIST *bsslst;
WlanGetNetworkBssList(hClientHandle,&pIfInfo->InterfaceGuid,&pBssList->Network [j].dot11Ssid ,pBssList->Network [j].dot11BssType ,true,NULL,&bsslst);
DesiredBssidList .Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
DesiredBssidList .Header.Revision = DOT11_BSSID_LIST_REVISION_1;
DesiredBssidList .Header.Size = sizeof(DOT11_BSSID_LIST);
DesiredBssidList .uNumOfEntries = 1; // If I change this to 0, it connects without a problem, but I can't control to which AP
DesiredBssidList .uTotalNumOfEntries = 1;
DesiredBssidList .BSSIDs[0][0]=bsslst->wlanBssEntries ->dot11Bssid[0] ;
DesiredBssidList .BSSIDs[0][1]=bsslst->wlanBssEntries ->dot11Bssid[1] ;
DesiredBssidList .BSSIDs[0][2]=bsslst->wlanBssEntries ->dot11Bssid[2] ;
DesiredBssidList .BSSIDs[0][3]=bsslst->wlanBssEntries ->dot11Bssid[3] ;
DesiredBssidList .BSSIDs[0][4]=bsslst->wlanBssEntries ->dot11Bssid[4] ;
DesiredBssidList .BSSIDs[0][5]=bsslst->wlanBssEntries ->dot11Bssid[5] ; wlanParam->pDesiredBssidList = &DesiredBssidList ;
}
else{
wlanParam->pDesiredBssidList = NULL ;
}
wlanParam ->wlanConnectionMode = wlan_connection_mode_profile;
wlanParam ->dot11BssType = pBssList->Network [j].dot11BssType ;
wlanParam ->dwFlags = 0 ;
printf("before pBssList->Network [j].dot11Ssid \n");
wlanParam ->pDot11Ssid = &pBssList->Network [j].dot11Ssid ;
printf("before ConvertToTchar\n");
wlanParam ->strProfile=(LPWSTR)SSidName;
wprintf(L"%s\n",wlanParam ->strProfile);

dwResult = WlanConnect(hClientHandle,&pIfInfo->InterfaceGuid ,wlanParam ,NULL);
if (dwResult != ERROR_SUCCESS)
{
wprintf(L"WlanConnect failed with error: %u\n",
dwResult);
dwRetVal = 1;
// You can use FormatMessage to find out why the function failed
}else{
wprintf(L"Connected successfully\n");
}
Try this code.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 30 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100