1。模擬器
int iNetwork;
HRESULT hResult = E_FAIL;
DWORD dwStatus = 0;
// cleanup the old connection
DestroyConnection(lpConnection);
// get the right network to connect to
//if(LB_ERR != iNetwork)
CONNMGR_DESTINATION_INFO DestInfo;
TInt i = 0;
for(i = 0; SUCCEEDED(ConnMgrEnumDestinations(i, &DestInfo)); i++)//枚舉存取點
{
// actually try to establish the connection
CONNMGR_CONNECTIONINFO ConnInfo;
ZeroMemory(&ConnInfo, sizeof(ConnInfo));
ConnInfo.cbSize = sizeof(ConnInfo);
ConnInfo.dwParams = CONNMGR_PARAM_GUIDDESTNET;
ConnInfo.dwPriority = CONNMGR_PRIORITY_USERBACKGROUND;
ConnInfo.guidDestNet = DestInfo.guid;
ConnInfo.hWnd = hDlg;
ConnInfo.uMsg = lpConnection->WM_CMEVENT;
hResult = ConnMgrEstablishConnectionSync(&ConnInfo, &lpConnection->hConnection,60000, &dwStatus);
// check to see if the attempt failed
if(SUCCEEDED(hResult))
{
break;
}
}
return hResult;
2。手機
HANDLE hConection;
DWORD dwStatus;
CONNMGR_CONNECTIONINFO sConInfo;
memset(&sConInfo, 0 ,sizeof(CONNMGR_CONNECTIONINFO));
CONNMGR_DESTINATION_INFO DestInfo;
TInt i = 0;
for(i = 0; SUCCEEDED(ConnMgrEnumDestinations(i, &DestInfo)); i++)
{
sConInfo.cbSize = sizeof(CONNMGR_CONNECTIONINFO);
sConInfo.dwParams = CONNMGR_PARAM_GUIDDESTNET;
sConInfo.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE;
sConInfo.dwFlags = CONNMGR_FLAG_PROXY_HTTP
|CONNMGR_FLAG_PROXY_WAP
|CONNMGR_FLAG_PROXY_SOCKS4
|CONNMGR_FLAG_PROXY_SOCKS5;
sConInfo.bExclusive = FALSE;
sConInfo.bDisabled = FALSE;
sConInfo.guidDestNet = DestInfo.guid;//IID_DestNetInternet
if (SUCCEEDED(ConnMgrEstablishConnectionSync(&sConInfo, &hConection, 60000, &dwStatus)))
{
return TRUE;
}
}
return FALSE;