如何从指定的GPRS连接点来连接网络?
我手机现在设置有多个GPSR连接点,比如CMWAP有WAP1,WAP2,CMNET有GPRS1,GPRS2,GPRS3,现在我想指定用GPRS2这个连接来连接GPRS,要怎么设置啊,现在我已经能得到这五个的GUID和对应的名称了即WAP1,WAP2,GPRS1,GPRS2,GPRS3,要程序从指定的GPRS连接点连接到网络,要怎么做?
附部分代码:
//列出所有的连接点的信息
struct ConInfo
{ WCHAR ConName[50];
GUID Aguid;
};
ConInfo AConInfo[10];
INT SelGPRS()
{
//Connection manager on Windows Mobile which exposes an api ConnMgrQueryDetailedStatus.This api can be used to query all the avaialble connections on the device. Following code snippet shows how:
//Variable Declaration
CONNMGR_CONNECTION_DETAILED_STATUS *pConnMgrDet = NULL;
HRESULT hResult;
DWORD dwBufferSize=0;
//Code Snippet
hResult=ConnMgrQueryDetailedStatus(pConnMgrDet,&dwBufferSize);
//This call the ConnMgrQueryDetailedStatus would return required buffer size in the dwBufferSizeParamater.
if(hResult==(HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)))
{
pConnMgrDet=(CONNMGR_CONNECTION_DETAILED_STATUS *)malloc(dwBufferSize);
hResult=ConnMgrQueryDetailedStatus(pConnMgrDet,&dwBufferSize);
}
//This would return a buffer hacing all the available connection informations.You can step through each using the pNext memeber of the structure.
int i = 0;
while(pConnMgrDet)
{
//Do what you want eg. if you want to check cellular network
if(pConnMgrDet->dwType==CM_CONNTYPE_CELLULAR)
{
wcscpy(AConInfo[i].ConName,pConnMgrDet->szDescription);
AConInfo[i].Aguid = pConnMgrDet->guidDestNet;
i++;
//Do some thing
}
pConnMgrDet=pConnMgrDet->pNext;
}
return i;
}
//GPRS连接
BOOL InitGPRS()
{
HANDLE hConnection;
DWORD dwStatus;
CONNMGR_CONNECTIONINFO sConInfo;
memset(&sConInfo, 0 ,sizeof(CONNMGR_CONNECTIONINFO));
sConInfo.cbSize = sizeof(CONNMGR_CONNECTIONINFO);
sConInfo.dwParams = CONNMGR_PARAM_GUIDDESTNET;
//最高优先级
sConInfo.dwPriority =CONNMGR_PRIORITY_USERBACKGROUND;// 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;
for (int i = 0;i<10;i++)
{
if (!wcscmp(AConInfo[i].ConName,L"GPRS2"))
{
MessageBox( NULL, AConInfo[i].ConName,TEXT("移动GIS系统"), MB_ICONINFORMATION | MB_OK );
sConInfo.guidDestNet = AConInfo[i].Aguid;//这里想用指定GUID来指定GPRS的接入点,不行,结果还是从程序自己选择的接入点连接了,一般是在连接设置中按顺序排列的第一个可用的接入点
break;
}
}
//sConInfo.guidDestNet = IID_DestNetInternet; //IID_DestNetWAP//这是默认的情况下的GUID,这里是程序自己去选择接入点
if (ConnMgrEstablishConnectionSync(&sConInfo, &hConnection, 30000, &dwStatus)==S_OK)
{
//MessageBox(NULL,L"Success",L"Success",MB_OK);
return TRUE;
}
else
{
//MessageBox(NULL,L"False",L"False",MB_OK);
return FALSE;
}
}
///////////////////////////////////////////////////////////////////////
//funciton:EstablishDatacall
//establish connection with web
//Output: IP code
//return value: BOOL
//////////////////////////////////////////////////////////////////////
BOOL EstablishDatacall(TCHAR *IPout)
{
CHAR szHostname[255];
TCHAR IP[17];
HOSTENT *pHostEnt=NULL;
int nAdapter = 0;
IN_ADDR *tsim=NULL;
BOOL tried2Connect=FALSE;
IP[0]=0; // Clear the IP Address
if (IPout!=NULL) IPout[0]=0;
nAdapter=0;
gethostname( szHostname, sizeof( szHostname ));
pHostEnt = gethostbyname( szHostname );
while ( pHostEnt!=NULL && pHostEnt->h_addr_list[nAdapter] )
{
// in case a device has multiple ethernet cards
// i.e. 802.11, Bluetooth, USB-Cradle
// we need to go though all pHostEnt->h_addr_list[nAdapter]
tsim=(IN_ADDR *)pHostEnt->h_addr_list[nAdapter];
if (tsim->S_un.S_un_b.s_b1==192 ||
tsim->S_un.S_un_b.s_b1==169 ||
tsim->S_un.S_un_b.s_b1==127 ||
tsim->S_un.S_un_b.s_b1==255)
// If you want to make sure you have a real Internet
// connection you cannot bet on IpAddresses starting with
// 127 and 255. 192 and 169 are local IP addresses and
// might be routed or proxied
nAdapter++;
else
{
wsprintf(IP,TEXT("%d.%d.%d.%d"),
tsim->S_un.S_un_b.s_b1,
tsim->S_un.S_un_b.s_b2,
tsim->S_un.S_un_b.s_b3,
tsim->S_un.S_un_b.s_b4);
if (IPout!=NULL)
{
wsprintf(IPout,IP);
return true;
}
}
}
return false;
}