rasEx.zip

  • PUDN用户
    了解作者
  • Visual C++
    开发工具
  • 3KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 7
    下载次数
  • 2005-09-25 08:09
    上传日期
一个可重用的RAS 类 作者:hangwire
rasEx.zip
  • RAS.h
    1.9KB
  • RAS.cpp
    6.2KB
  • www.pudn.com.txt
    218B
内容介绍
// RAS.cpp: implementation of the CRAS class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "RAS.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CRAS::CRAS() { Reset(); Initialize(); } CRAS::~CRAS() { Finalize(); } BOOL CRAS::Initialize() { m_hRASDll = LoadLibrary("RASAPI32.DLL"); LoadPhonebook(); return IsInitialized(); } void CRAS::Reset() { m_hRASDll = NULL; m_ulEntryCount = 0; m_hConnection = NULL; } BOOL CRAS::IsInitialized() { return (m_hRASDll != NULL); } BOOL CRAS::Finalize() { if (IsInitialized()) return FreeLibrary(m_hRASDll); else return TRUE; } BOOL CRAS::LoadPhonebook() { if (!IsInitialized()) return FALSE; unsigned long ulEntryCount = sizeof(RASENTRYNAME) * 20; ZeroMemory(m_Entries, sizeof(RASENTRYNAME) * 20); m_Entries[0].dwSize = sizeof(RASENTRYNAME); CRASEnumEntries pRASEnumEntries = (CRASEnumEntries)GetProcAddress(m_hRASDll, "RasEnumEntriesA"); if (pRASEnumEntries) { pRASEnumEntries(NULL, NULL, m_Entries, &ulEntryCount, &m_ulEntryCount); return TRUE; } else return FALSE; } CString CRAS::GetEntry(ULONG ulIndex) { if ((ulIndex >=0) && (ulIndex < m_ulEntryCount)) return m_Entries[ulIndex].szEntryName; else return ""; } BOOL CRAS::Dial(CString sEntry, CString sUserName, CString sPassword, CRASCallback pfnCallback, CString sDomain) { if (!IsInitialized()) return FALSE; RASDIALEXTENSIONS extensions; ZeroMemory(&extensions, sizeof(RASDIALEXTENSIONS)); extensions.dwSize = sizeof(RASDIALEXTENSIONS); extensions.dwfOptions = RDEOPT_UsePrefixSuffix; RASDIALPARAMS params; ZeroMemory(&params, sizeof(params)); params.dwSize = sizeof(params); strcpy(params.szEntryName, sEntry); ZeroMemory(params.szPhoneNumber, RAS_MaxPhoneNumber + 1); ZeroMemory(params.szCallbackNumber, RAS_MaxCallbackNumber + 1); ZeroMemory(params.szUserName, UNLEN + 1); ZeroMemory(params.szPassword, PWLEN + 1); ZeroMemory(params.szDomain, DNLEN + 1); #if (WINVER >= 0x401) dwSubEntry = 0; params.dwCallbackId = 0; #endif strcpy(params.szUserName, sUserName); strcpy(params.szPassword, sPassword); strcpy(params.szDomain, sDomain); CRASDial pRASDial = (CRASDial)GetProcAddress(m_hRASDll, "RasDialA"); if (pRASDial) return !pRASDial(&extensions, NULL, &params, 0, pfnCallback, &m_hConnection); else return FALSE; } BOOL CRAS::HangUp() { if (!IsInitialized()) return FALSE; CRASHangUp pRASHangUp = (CRASHangUp)GetProcAddress(m_hRASDll, "RasHangUpA"); BOOL result = !pRASHangUp(m_hConnection); if (result) m_hConnection = NULL; return result; } CString CRAS::GetStringState(RASCONNSTATE rasconnstate) { if ( (rasconnstate == RASCS_OpenPort) || (rasconnstate == RASCS_PortOpened) || (rasconnstate == RASCS_ConnectDevice) || (rasconnstate == RASCS_SubEntryConnected) ) return "Dialing remote server"; if ( (rasconnstate == RASCS_DeviceConnected) || (rasconnstate == RASCS_AllDevicesConnected) ) return "Remote server connected"; if ( (rasconnstate == RASCS_Authenticate) || (rasconnstate == RASCS_AuthNotify) || (rasconnstate == RASCS_AuthRetry) || (rasconnstate == RASCS_AuthCallback) || (rasconnstate == RASCS_AuthProject) || (rasconnstate == RASCS_AuthLinkSpeed) || (rasconnstate == RASCS_AuthAck) || (rasconnstate == RASCS_ReAuthenticate) || (rasconnstate == RASCS_Authenticated) || (rasconnstate == RASCS_StartAuthentication) || (rasconnstate == RASCS_RetryAuthentication) ) return "Authentificating at remote server"; if (rasconnstate == RASCS_AuthChangePassword) return "You must change password"; if (rasconnstate == RASCS_PasswordExpired) return "Password expired"; if ( (rasconnstate == RASCS_PrepareForCallback) || (rasconnstate == RASCS_WaitForModemReset) || (rasconnstate == RASCS_WaitForCallback) || (rasconnstate == RASCS_CallbackComplete) ) return "Processing modem callback"; if ( (rasconnstate == RASCS_LogonNetwork) || (rasconnstate == RASCS_Connected) ) return "Logging on network"; if ( (rasconnstate == RASCS_SubEntryDisconnected) || (rasconnstate == RASCS_Disconnected) ) return "Disconnected from remote server"; return "Unrecognized RAS state"; } CString CRAS::GetStringError(DWORD dwError) { CRASGetErrorString pRASGetErrorString = (CRASGetErrorString)GetProcAddress(m_hRASDll, "RasGetErrorStringA"); if (pRASGetErrorString) { char *pszErrorString = new char[1024]; CString sResult; ZeroMemory(pszErrorString, 1024); if (!pRASGetErrorString(dwError, pszErrorString, 1024)) sResult = pszErrorString; else sResult = "Unable to retrieve RAS error message text"; delete[] pszErrorString; return sResult; } return "Unable to retrieve RAS error message text"; } ULONG CRAS::GetEntryCount() { return m_ulEntryCount; } BOOL CRAS::IsConnected() { return (m_hConnection != NULL); } BOOL CRAS::IsEntryConnected(CString sEntry) { if (!IsInitialized()) return FALSE; CRASEnumConnections pRASEnumConnections = (CRASEnumConnections)GetProcAddress(m_hRASDll, "RasEnumConnectionsA"); CRASGetConnectStatus pRASGetConnectStatus = (CRASGetConnectStatus)GetProcAddress(m_hRASDll, "RasGetConnectStatusA"); if ((!pRASEnumConnections) || (!pRASGetConnectStatus)) return FALSE; DWORD dwSize = sizeof(RASCONN) * 20, dwCount = 20; HRASCONN hConnection = NULL; RASCONN connections[20]; connections[0].dwSize = sizeof(RASCONN); if (!pRASEnumConnections(connections, &dwSize, &dwCount)) { for (DWORD i=0; i<dwCount; i++) if (sEntry == connections[i].szEntryName) { hConnection = connections[i].hrasconn; break; } } else return FALSE; if (!hConnection) return FALSE; RASCONNSTATUS status; status.dwSize = sizeof(RASCONNSTATUS); if (!pRASGetConnectStatus(hConnection, &status)) return (status.rasconnstate == RASCS_Connected); else return FALSE; }
评论
    相关推荐
    • ras
      一个拨号及监视拨号状况的例子
    • Ras.rar
      VC 实现Ras 拨号上网 在windows NT下使用
    • RASAsynchronous.rar
      RAS异步拨号连接程序,实现拨号连接的功能
    • VC_RAS.rar
      VC++6 RAS高级编程
    • RAS.rar
      拨号软件源代码,指定帐号和密码,程序自动拨号
    • duankailianjie.rar
      一个断开宽带连接再次连接的例子.非常实用.
    • chap09ras.rar
      RAS高级编程实例,为Visual C++.NET网络与通信高级编程范例九章的配套源代码
    • DSP1.rar
      几个简单的DSP应用例程,供大家参考学习
    • 21855256chap09ras.rar
      Visual C++ .NET 网络与通信高级编程范例配套代码
    • qpopper2.53.tar.Z
      pop3 server