RAS拨号软件源代码 V2.0

RAS拨号软件源代码 V2.0
  发表日期:2005年10月10日   出处:www.59hao.com/chx    作者:陈红秀     【编辑录入:webmaster】
 

花了2天时间做的一个软件,希望大家喜欢~~,Visual C++ 6.0编写,主要用到了多线程编程和网络编程中的几个RAS API函数

需要包含的头文件:

#include <ras.h>
#pragma comment(lib, "Rasapi32.lib")


主要的源代码如下:

             
            
            
            
void CRRDlg::RAS_Close() //关闭当前使用中的拨号连接{ m_bClosing = true; SetDlgItemText(IDC_CONNECT_STATE, "正在关闭当前的网络连接,请稍候..."); RASCONN ras[20]; DWORD dwSize, dwNumber, dwCount; ras[0].dwSize = sizeof(RASCONN); dwSize = sizeof(ras); if (::RasEnumConnections(ras, &dwSize, &dwNumber) == 0) { for (dwCount = 0; dwCount < dwNumber; dwCount++) //依次关闭所有的连接 { if (::RasHangUp(ras[dwCount].hrasconn) != 0) //如果函数成功,则返回0 { break; } } } SetDlgItemText(IDC_STATIC_IP, ""); // SetDlgItemText(IDC_STATIC2,""); // SetDlgItemText(IDC_STATIC3,""); // SetDlgItemText(IDC_STATIC4,""); SetDlgItemText(IDC_CONNECT_STATE, "网络连接已经关闭!"); m_bConnected = false; m_bClosing = false; if (::IsWindowVisible(GetSafeHwnd())) { this->CheckNet(); }}

UINT CRRDlg::RAS_Connect(){ m_bConnecting = true; //正在连接,不能关闭程序 SetDlgItemText(IDC_CONNECT_STATE, "正在连接拨号网络,请稍候..."); CString strEntryName; m_list.GetText(m_list.GetCurSel(), strEntryName); char szUserName[MAX_PATH], szPassword[MAX_PATH]; GetDlgItemText(IDC_EDIT_USERNAME, szUserName, MAX_PATH); GetDlgItemText(IDC_EDIT_PASSWORD, szPassword, MAX_PATH); HRASCONN hRasConn = NULL; RASDIALPARAMS rdParams; //拨号连接的信息 ZeroMemory(&rdParams, sizeof(RASDIALPARAMS)); rdParams.dwSize = sizeof(RASDIALPARAMS); lstrcpy(rdParams.szEntryName, strEntryName); lstrcpy(rdParams.szUserName, szUserName); lstrcpy(rdParams.szPassword, szPassword); DWORD dwRet; dwRet = ::RasDial(NULL, NULL, &rdParams, 0L, NULL, &hRasConn); if (dwRet) //如果函数成功,则返回0 { char szBuf[256] = ""; ::RasGetErrorString((UINT)dwRet, (LPSTR)szBuf, 256); SetDlgItemText(IDC_CONNECT_STATE, CString("连接错误! ") + CString(szBuf) ); AfxBeginThread(sndError, this); m_bConnecting = false; WinExec("rasphone -a", SW_SHOW); return 0; } /*----------------------------------------------------------------------*/ RASPPPIP raspppip; //获取拨号连接的IP地址 raspppip.dwSize = sizeof(RASPPPIP); DWORD cb = sizeof(RASPPPIP); ::RasGetProjectionInfo(hRasConn, RASP_PppIp, &raspppip, &cb); m_strIP = (CString)raspppip.szIpAddress; SetDlgItemText(IDC_STATIC_IP, m_strIP); /*----------------------------------------------------------------------*/ SetDlgItemText(IDC_CONNECT_STATE, "已经成功地建立了连接"); m_bConnected = true; m_bConnecting = false; if (::IsWindowVisible(GetSafeHwnd())) this->CheckNet(); return 1;}

 


你可能感兴趣的:(RAS拨号软件源代码 V2.0)