1. Simulator
Int inetwork;
Hresult = e_fail;
DWORD dwstatus = 0;
// Cleanup the old connection
Destroyconnection (lpconnection );
// Get the right network to connect
// If (lb_err! = Inetwork)
Connmgr_destination_info destinfo;
Tint I = 0;
For (I = 0; succeeded (connmgrenumdestinations (I, & destinfo); I ++) // enumerate Access Points
{
// 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. Mobile phone
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;