//---------------------------------------------------------------------------
bool __fastcall TForm1::StartADSL()
{
RASDIALPARAMS rdParams;
DWORD dwRet;
rdParams.dwSize=sizeof(RASDIALPARAMS);
strcpy(rdParams.szEntryName,"宽带连接");
strcpy(rdParams.szPhoneNumber,"");
strcpy(rdParams.szCallbackNumber,"*");
strcpy(rdParams.szUserName,Edit2->Text.c_str());
strcpy(rdParams.szPassword,Edit3->Text.c_str()); //szPassword="";
strcpy(rdParams.szDomain,"");
HRASCONN hRasConn=NULL;
dwRet=RasDial(NULL,NULL,&rdParams,0L,NULL,&hRasConn);
if(dwRet!=0)
{
Application->MessageBoxA("未连接","警告",0);
//deal with error…
return false;
}
else
{
RASPPPIP raspppip; //获取拨号连接的IP地址
raspppip.dwSize = sizeof(RASPPPIP);
DWORD cb = sizeof(RASPPPIP);
::RasGetProjectionInfo(hRasConn, RASP_PppIp, &raspppip, &cb);
Label2->Caption = raspppip.szIpAddress ;
//
//Sleep(1000);
}
return true;
}
//---------------------------------------------------------------------
//---------------------------------------------------------------------------
bool __fastcall TForm1::CloseADSL()
{
bool bReturn= false;
RASCONN ras[20];
DWORD dSize, dNumber, dCount;
//函数RasEnumConnections()的要求
ras[0].dwSize=sizeof(RASCONN);
dSize =sizeof(ras);
if (RasEnumConnections(ras,&dSize,&dNumber)==0)
{
bReturn=true;
Memo1->Lines->Add(ras[0].szEntryName);
Memo1->Lines->Add(ras[0].szDeviceName);
// ras[0].
//依次关闭所有的连接
for (dCount=0; dCount<dNumber; dCount++)
{
if (RasHangUp(ras[dCount].hrasconn)!=0)
{
bReturn=false;
break;
}
}
}
return bReturn;
}
//---------------------------------------------------------------------------