A recent program to write a medical program, using Windows Mobile to do communications, requires that the data from the phone's end be sent over GPRS to a server on the public web. Data transfer I used the socket, with data line +activesync debugging through, normal data transmission, in preparation for the software to be submitted to the Quality Inspection department, with the real GPRS to do the communication test, the problem comes out, the connection is always built, but the mobile phone's IE browser can normally open the Web page, And strange is that as long as the use of IE browser successfully visited a Web page, my socket can be normal data communication, it seems that the legendary GPRS often connected by me misunderstood.
Mobile phone opened GPRS, our socket program can not directly establish a network connection, need to use Connection Manager to obtain the current available connections, and automatically select an optimal connection path, and then enable this connection, after the successful connection started with the socket for network connection can be normal. Probably GPRS dialing and connection process is here automatically. The source code encapsulates a connection-managed class and test code to see exactly what Windows Mobile needs to do before the socket is programmed.
You first need to enumerate the currently available connections
void CConnectManager::EnumNetIdentifier ( OUT CStringArray &StrAry )
{
CONNMGR_DESTINATION_INFO networkDestInfo = {0};
// 得到网络列表
for ( DWORD dwEnumIndex=0; ; dwEnumIndex++ )
{
memset ( &networkDestInfo, 0, sizeof(CONNMGR_DESTINATION_INFO) );
if ( ConnMgrEnumDestinations ( dwEnumIndex, &networkDestInfo ) == E_FAIL )
{
break;
}
StrAry.Add ( networkDestInfo.szDescription );
}
}
Next, find the Internet connection, which can be done using remote URL mapping, which allows the system to automatically pick a best connection.
int CConnectManager::MapURLAndGUID ( LPCTSTR lpszURL, OUT GUID &guidNetworkObject, OUT CString *pcsDesc/*=NULL*/ )
{
if ( !lpszURL || lstrlen(lpszURL) < 1 )
return FALSE;
memset ( &guidNetworkObject, 0, sizeof(GUID) );
int nIndex = 0;
HRESULT hResult = ConnMgrMapURL ( lpszURL, &guidNetworkObject, (DWORD*)&nIndex );
if ( FAILED(hResult) )
{
nIndex = -1;
DWORD dwLastError = GetLastError ();
AfxMessageBox ( _T("Could not map a request to a network identifier") );
}
else
{
if ( pcsDesc )
{
CONNMGR_DESTINATION_INFO DestInfo = {0};
if ( SUCCEEDED(ConnMgrEnumDestinations(nIndex, &DestInfo)) )
{
*pcsDesc = DestInfo.szDescription;
}
}
}
return nIndex;
}