#include <Ras.h>
#include <RasError.h>
#pragma comment(lib, "RasApi32.lib")
HRASCONN RasGetConnection(TCHAR *lpName)
{
HRASCONN hRet;
LPRASCONN lpConn;
DWORD cbConn;
DWORD cbOpt;
DWORD dwRet;
hRet = NULL;
lpConn = NULL;
cbConn = 0;
dwRet = RasEnumConnections(lpConn, &cbConn, &cbOpt);
if (dwRet == ERROR_BUFFER_TOO_SMALL || dwRet == ERROR_NOT_ENOUGH_MEMORY)
{
if (lpConn = (LPRASCONN)GlobalAlloc(GPTR, cbConn))
{
lpConn[0].dwSize = sizeof(RASCONN);
if (RasEnumConnections(lpConn, &cbConn, &cbOpt) == 0)
{
for (DWORD i = 0; i < cbOpt; i++)
{
if (lstrcmpi(lpConn[i].szEntryName, lpName) == 0)
{
hRet = lpConn[i].hrasconn;
break; // for i
}
}
}
GlobalFree(lpConn);
}
}
return hRet;
}
BOOL RasDisConnect(HRASCONN RasConn)
{
return (RasHangUp(RasConn) == 0);
}
BOOL RasReDial(TCHAR *lpName, TCHAR *PassWord)
{
HRASCONN hRas;
RASDIALPARAMS rdp;
BOOL IsGetPassword;
if (hRas = RasGetConnection(lpName))
{
if (!RasDisConnect(hRas))
{
return FALSE;
}
Sleep(10 * 1000);
hRas = NULL;
}
memset(&rdp, 0, sizeof(rdp));
rdp.dwSize = sizeof(rdp);
lstrcpyn(rdp.szEntryName, lpName, _countof(rdp.szEntryName));
if (RasGetEntryDialParams(NULL, &rdp, &IsGetPassword) == 0)
{
lstrcpyn(rdp.szPassword, PassWord, _countof(rdp.szPassword));
if (RasDial(NULL, NULL, &rdp, 0, NULL, &hRas) == 0)
{
return TRUE;
}
}
return FALSE;
}
ADSL拨号
最新推荐文章于 2022-07-11 07:36:00 发布