PDA PPC连接网络 Connection Manager Sample Code

[MS Smartphone] Connection Manager Sample Code 收藏
/**********************************************************************************
*Function:GPRSConnect()
**Description:If there is active CMNET connection,no need to create CMNET connection again.
*If no active connection,then create a CMNET connection,
*Input:N/A
*Output:N/A
*Return:BOOL,TRUE-Success FALSE-FAILURE
*Others:None
***********************************************************************************/


BOOL GPRSConnect()
{

int ret=CloseRasGPRSConnections();
if(1==ret)
return TRUE;
else if(0==ret)
return GPRSCmnetConnect();
else
     return FALSE;
}

/**********************************************************************************
*Function:GPRSCmnetConnect()
*Description:Create CMNET GPRS connection
*Input:N/A
*Output:N/A
*Return:BOOL,TRUE-Success FALSE-FAILURE
*Others:None
***********************************************************************************/


BOOL GPRSCmnetConnect()
{
HANDLE hConnection = NULL;

DWORD   dwIndex = 0;
DWORD   dwResult = 0;
DWORD   dwStatus = 0;
BOOL   tResult   = FALSE;
CONNMGR_CONNECTIONINFO sCI = { 0 };
HRESULT hResult = S_OK;
   
sCI.cbSize           = sizeof(sCI);
sCI.dwParams         = CONNMGR_PARAM_GUIDDESTNET;
sCI.dwFlags          = CONNMGR_FLAG_PROXY_HTTP | CONNMGR_FLAG_PROXY_WAP | CONNMGR_FLAG_PROXY_SOCKS4 | CONNMGR_FLAG_PROXY_SOCKS5;      
sCI.dwPriority       = CONNMGR_PRIORITY_USERINTERACTIVE;
sCI.guidDestNet      = IID_DestNetInternet;

if (FAILED(ConnMgrEstablishConnectionSync(&sCI, &hConnection, 30000, &dwStatus)))
{
     return FALSE;
}

return TRUE;
}

/**********************************************************************************
*Function:ClosRasGPRSConnections()
*Description:If there is active CMNET connection,don't close it,because we need
*CMNET connection in our program.If there is active CMWAP connection,we disconnect it.
*Input:N/A
*Output:N/A
*Return:DWORD,0-no active connection(CMWAP),1-cmnet is active,-1-error happened
*Others:None
***********************************************************************************/

DWORD CloseRasGPRSConnections()
{
int index; // An integer index
DWORD dwError, dwRasConnSize, dwNumConnections; // Number of connections found
RASCONN RasConn[20]; // Buffer for connection state data,Assume the maximum number of entries is 20.

TCHAR CMNET[64]=_T("GPRS连接互联网");
TCHAR CMWAP[64]=_T("移动梦网(GPRS)");


// Assume no more than 20 connections.
RasConn[0].dwSize = sizeof (RASCONN);
dwRasConnSize = 20 * sizeof (RASCONN);

// Find all connections.
if (dwError = RasEnumConnections (RasConn, &dwRasConnSize,&dwNumConnections))
{
return -1;
}


// If there are no connections, return zero.
if (!dwNumConnections)
{
return 0;
}


// Terminate all of the remote access connections.
for (index = 0; index < (int)dwNumConnections; ++index)
{

if(!wcscmp(RasConn[index].szEntryName,CMWAP))
{
   if (dwError = RasHangUp (RasConn[index].hrasconn))
    return -1;
   else
    return 0; //successfully disconnect cmwap;

}

if(wcscmp(RasConn[index].szEntryName,CMNET)==0){
   return 1;

}

}

return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值