Hello,our OS (WEC7) contains connection manager so we have to use connection manager api to make connection to wifi. Our system should reconnect automatically to an access point after reboot.After establishing a connection using onscreen connection manager I retrieve configuration with CmGetConnectionConfig(SSID, pConfig, &cbSize)and store the configuration in a file (it is about 2 kilobytes, most of them contains xml-information).After reboot I use this file to populate a Config struct, according following code:#define SSID L"Connectify-me" CM_CONNECTION_DETAILS *pDetails = NULL; CM_SESSION_HANDLE myhandle = CmCreateSession(); CM_CONNECTION_HANDLE hConnection = NULL; CM_RESULT result; CM_CONNECTION_CONFIG* pConfig = NULL; DWORD cbConfigSize = 10; unsigned char * ptr = (unsigned char *)pConfig; FILE * fp = _wfopen(L"\\flashdisk\\wifi.txt",L"rb"); if (fp) { fseek(fp,0,SEEK_END); cbConfigSize = ftell(fp); fseek(fp,0,SEEK_SET); pConfig = (CM_CONNECTION_CONFIG*)LocalAlloc(0, cbConfigSize); int numread = 0; if (pConfig) numread = fread(pConfig,1,cbConfigSize,fp); fclose(fp); } if (pConfig) { result = CmAddConnectionConfig(SSID,pConfig,cbConfigSize); LocalFree(pConfig); } Sleep(5000); for (result = CmGetFirstCandidateConnection(myhandle, NULL, CMSO_DEFAULT, &hConnection);result==CMRE_SUCCESS; result = CmGetNextCandidateConnection(myhandle, &hConnection)) { DWORD dwError = GetConnectionDetailsByHandle(hConnection, &pDetails); if (dwError==0) { if (memcmp(&pDetails->Type, &CM_CSP_WIFI_TYPE, sizeof(CM_CONNECTION_TYPE)) == 0) { if (wcscmp(pDetails->szName,SSID) == 0) { result = CmAcquireConnection(hConnection); int aa = 0; } } } } CmCloseSession(myhandle); }DWORD GetConnectionDetailsByHandle(CM_CONNECTION_HANDLE hConnection, CM_CONNECTION_DETAILS** ppDetails){ DWORD dwError = ERROR_SUCCESS; CM_RESULT result = CMRE_INSUFFICIENT_BUFFER; CM_CONNECTION_DETAILS* pDetails = NULL; DWORD dwDetailSize = 255; // Get the connection details. for (int i = 0; i < MAX_TRY_COUNT_FOR_INSUFFICIENT_BUFFER && result == CMRE_INSUFFICIENT_BUFFER; i++) { LocalFree(pDetails); pDetails = (CM_CONNECTION_DETAILS *)LocalAlloc(0, dwDetailSize); if (pDetails) result = CmGetConnectionDetailsByHandle(hConnection,pDetails,&dwDetailSize); } *ppDetails = pDetails; pDetails = NULL; LocalFree(pDetails); return dwError;} CmAddConnectionConfig(SSID,pConfig,cbConfigSize) returns CMRE_SUCCESS, but CmAcquireConnection(hConnection) returns CMRE_CONNECTION_ACQUIRE_FAILED.On screen in wifi connect dialog Ii see FAILED TO ASSOCIATE WITH ssid.When I have a look into registry HKLM\Comm\Connmgr\Settings\Connections\ssid I see that field Data 0 is much larger (3088 compared to 2280) than it is when the connection is establised using on screen connection dialog.What is going wrong ?Is there another way for automatic reconnection to an access point ?Any ideas welcome !Thank you ! 解决方案 Hello,after many trials I think I have found the reason for the problem: in the xml-part of the configuration that I get with CmGetConnectionDetailsByHandle the password is protected <keyType>passPhrase</keyType> <protected>true</protected>I think that CmAcquireConnection does not know how to deal with protected keys. 这篇关于WEC7,使用连接管理器api连接wifi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-02 00:07