WEB开发网
开发学院手机开发Windows Mobile 开发 Windows Mobile中如何建立GPRS连接以便Socket能正... 阅读

Windows Mobile中如何建立GPRS连接以便Socket能正常通信

 2010-08-22 12:42:00 来源:WEB开发网   
核心提示:(DWORD*)&nIndex );if ( FAILED(hResult) ){nIndex = -1;DWORD dwLastError = GetLastError ();AfxMessageBox ( _T("Could not map a request to a network identifie
(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;

}

以下代码是用来启用指定编号的连接

BOOL CConnectManager::EstablishConnection ( DWORD dwIndex )

{

ReleaseConnection ();

// 得到正确的连接信息

CONNMGR_DESTINATION_INFO DestInfo = {0};

HRESULT hResult = ConnMgrEnumDestinations(dwIndex, &DestInfo);

BOOL bRet = FALSE;

if(SUCCEEDED(hResult))

{

// 初始化连接结构

CONNMGR_CONNECTIONINFO ConnInfo;

ZeroMemory(&ConnInfo, sizeof(ConnInfo));

ConnInfo.cbSize = sizeof(ConnInfo);

ConnInfo.dwParams = CONNMGR_PARAM_GUIDDESTNET;

ConnInfo.dwFlags = CONNMGR_FLAG_PROXY_HTTP |

CONNMGR_FLAG_PROXY_WAP |

CONNMGR_FLAG_PROXY_SOCKS4 |

CONNMGR_FLAG_PROXY_SOCKS5;

ConnInfo.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE;

ConnInfo.guidDestNet = DestInfo.guid;

ConnInfo.bExclusive = FALSE;

ConnInfo.bDisabled = FALSE;

DWORD dwStatus = 0;

hResult = ConnMgrEstablishConnectionSync(&ConnInfo, &m_hConnection, 10*1000, &dwStatus );

if(FAILED(hResult))

{

m_hConnection = NULL;

}

else bRet = TRUE;

}

return bRet;

}

为了确保连接是否真正可用,需要检测连接状态,在规定的时间内如果未取得“连接成功”的状态,则认为连接未能正常启用,可能需要配置手机的连接管理器界面

Tags:Windows Mobile 如何

编辑录入:coldstar [复制链接] [打 印]
赞助商链接