|
int ConnInit(HRASCONN * lp_hConection)
{
HRESULT hr = -1;
TCHAR * pszDmConnName = NULL;
RASCONN rc;
DWORD dwSize = 0;
DWORD cnt;
int i;
RASCONN * pRc = NULL;
RASDIALPARAMS rasDial;
ZeroMemory(&rc, sizeof(rc));
pszDmConnName = _T("cmnet对应的GPRS Name"); //APN =cmnet
*lp_hConection = NULL;
dwSize = rc.dwSize = sizeof(rc);
(void)RasEnumConnections(&rc, &dwSize, &cnt);
mvaTrace(1, "DMConnInit +++++++ RasEnumConnections = %d", cnt);
if (cnt > 0)
{
pRc = &rc;
for (i = 0; (unsigned long)i!=cnt; i++)
{
hr = wcscmp((pRc+i)->szEntryName, pszDmConnName);
if ( 0 == hr)
{
/* 找到连接,将连接标示句柄带回 */
*lp_hConection = (pRc+i)->hrasconn;
return hr;
}
}
/* 已经有一个别的连接,暂不拨号 */
hr = 1;
}
else
{
memset(&rasDial, 0, sizeof(RASDIALPARAMS));
rasDial.dwSize = sizeof(RASDIALPARAMS);
(void)wcscpy(rasDial.szEntryName, pszDmConnName);
/* 正式发起拨号,根据连接名称 */
hr = (int)RasDial(NULL, NULL, &rasDial, 0, NULL, lp_hConection);
}
return (int)hr;
}
int ConnRelease(HRASCONN hConection)
{
return (int)RasHangUp(hConection);
} |
|