Click here to Skip to main content
15,891,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Updated 22-Feb-10 0:59am
v2

Try ASSERT(hClientHanle); at debugging... :)
 
Share this answer
 
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900