// RasClient.cpp
// Copyright� 1998 Qing Zhang (qzhang7@tfn.net)
// 8/10/98 Create on Win95
// 8/19/98, 11/4/98 Modify on NT4
// You are free to use and distribute this source, as long as there is
// no change, and this comment stays intact.
#include "stdafx.h"
#include "RasClient.h"
CRasClient::CRasClient()
{
ZeroMemory(&m_rasStatus, sizeof(m_rasStatus));
m_rasStatus.dwSize = sizeof(m_rasStatus);
m_ConnectionHandle = NULL;
}
CRasClient::~CRasClient()
{
}
long CRasClient::GetDeviceCount()
{
DWORD dwSize = 0;
DWORD dwNumOfDevices = 0;
RasEnumDevices(NULL, &dwSize, &dwNumOfDevices);
return dwNumOfDevices;
}
BOOL CRasClient::GetDeviceNameType(int nIndex,
CString& strName, CString& strType)
{
BOOL bResult = FALSE;
DWORD dwSize = 0;
DWORD dwNumOfDevices = 0;
DWORD dwRV = RasEnumDevices(NULL, &dwSize, &dwNumOfDevices);
if(nIndex >= (int)dwNumOfDevices &&
nIndex < 0)
{
TRACE("BAD DEVICE INDEX!");
return FALSE;
}
RASDEVINFO *lpRdi = new RASDEVINFO[dwNumOfDevices];
lpRdi->dwSize = sizeof(*lpRdi);
dwRV = RasEnumDevices(lpRdi, &dwSize, &dwNumOfDevices);
if(dwRV == 0)
{
strName = lpRdi[nIndex].szDeviceName;
strType = lpRdi[nIndex].szDeviceType;
bResult = TRUE;
}
delete []lpRdi;
return bResult;
}
BOOL CRasClient::GetModemName(CString* strModemNameArray)
{
DWORD dwSize = 0;
DWORD dwNumOfDevices = 0;
DWORD dwRV = RasEnumDevices(NULL, &dwSize, &dwNumOfDevices);
RASDEVINFO *lpRdi = new RASDEVINFO[dwNumOfDevices];
lpRdi->dwSize = sizeof(*lpRdi);
dwRV = RasEnumDevices(lpRdi, &dwSize, &dwNumOfDevices);
if(dwRV != 0)
{
delete []lpRdi;
return FALSE;
}
CString strType;
int j = 0;
for(int i = 0; i < (int)dwNumOfDevices; i++)
{
strType = lpRdi[i].szDeviceType;
if(strType.CompareNoCase("MODEM") == 0) // = "RASDT_Modem";
{
strModemNameArray[j] = lpRdi[i].szDeviceName;
j++;
}
}
delete []lpRdi;
return TRUE;
}
long CRasClient::GetModemCount()
{
DWORD dwSize = 0;
DWORD dwNumOfDevices = 0;
DWORD dwRV = RasEnumDevices(NULL, &dwSize, &dwNumOfDevices);
RASDEVINFO *lpRdi = new RASDEVINFO[dwNumOfDevices];
lpRdi->dwSize = sizeof(*lpRdi);
dwRV = RasEnumDevices(lpRdi, &dwSize, &dwNumOfDevices);
if(dwRV != 0)
{
delete []lpRdi;
return -1;
}
CString strType;
int nModemCount = 0;
for(int i = 0; i < (int)dwNumOfDevices; i++)
{
strType = lpRdi[i].szDeviceType;
if(strType.CompareNoCase("MODEM") == 0) // = "RASDT_Modem";
nModemCount++;
}
delete []lpRdi;
return nModemCount;
}
DWORD CRasClient::ChangeEntryName(CString strOldName, CString strNewName)
{
LPTSTR lpszEntry = strOldName.GetBuffer(1);
strOldName.ReleaseBuffer();
if(RasValidateEntryName(NULL, lpszEntry) != ERROR_ALREADY_EXISTS)
{
// GET ENTRY
BYTE bDeviceInfo = NULL;
DWORD dwDeviceInfoSize = sizeof(bDeviceInfo);
DWORD dwEntrySize = 0;
DWORD dwRV;
RASENTRY entry;
entry.dwSize = sizeof(entry);
dwRV = RasGetEntryProperties(NULL, lpszEntry, &entry, &dwEntrySize,
&bDeviceInfo, &dwDeviceInfoSize); // GET 603
dwRV = RasGetEntryProperties(NULL, lpszEntry, &entry, &dwEntrySize,
&bDeviceInfo, &dwDeviceInfoSize); // GET 0
if(dwRV == 0)
{
LPTSTR lpszNewName = strNewName.GetBuffer(1);
strNewName.ReleaseBuffer();
dwRV = RasSetEntryProperties(NULL, (char*)lpszNewName, &entry,
sizeof(entry), NULL, 0);
return dwRV;
}
else
return dwRV;
}
return ERROR_ENTRY_NO_FOUND;
}
DWORD CRasClient::CreateNewEntry(CString strEntry,
CString strDeviceType,
CString strDeviceName,
DWORD dwfNetProtocols, DWORD dwFrameProtocal,
CString strLocalPhone,
CString strPhoneBook /*=NULL*/)
{
LPTSTR lpszEntry = strEntry.GetBuffer(1);
strEntry.ReleaseBuffer();
LPTSTR lpszPhoneBook = strPhoneBook.GetBuffer(1);
if(strPhoneBook == _T(""))
lpszPhoneBook = NULL;
strPhoneBook.ReleaseBuffer();
if(RasValidateEntryName(lpszPhoneBook, lpszEntry) != ERROR_ALREADY_EXISTS)
{
RASENTRY rasEntry;
::ZeroMemory(&rasEntry, sizeof(rasEntry));
rasEntry.dwSize = sizeof(rasEntry);
strcpy(rasEntry.szLocalPhoneNumber, strLocalPhone);
rasEntry.dwfNetProtocols = dwfNetProtocols;
rasEntry.dwFramingProtocol = dwFrameProtocal;
// DON'T USE "RASDT_Modem", use "modem", otherwise dwRV = 87
strcpy(rasEntry.szDeviceType, strDeviceType);
strcpy(rasEntry.szDeviceName, strDeviceName);
rasEntry.dwfOptions=RASEO_RemoteDefaultGateway|RASEO_ModemLights|RASEO_SwCompression;//指示+软压缩//远程默认网关
DWORD dwRV = RasSetEntryProperties(lpszPhoneBook, (char*)lpszEntry, &rasEntry,
sizeof(rasEntry), NULL, 0);
return dwRV;
}
return ERROR_ALREADY_EXISTS;
}
DWORD CRasClient::SetEntryOption(CString strEntry, DWORD dwfOptions,
BOOL bSet, CString strPhoneBook /*=_T("")*/)
{
LPTSTR lpszEntry = strEntry.GetBuffer(1);
strEntry.ReleaseBuffer();
LPTSTR lpszPhoneBook = strPhoneBook.GetBuffer(1);
if(strPhoneBook == _T(""))
lpszPhoneBook = NULL;
strPhoneBook.ReleaseBuffer();
RASENTRY entry;
DWORD dwRV = GetEntryProperties(strEntry, &entry, lpszPhoneBook);
if(dwRV == 0)
{
if(bSet)
entry.dwfOptions |= dwfOptions;
else
entry.dwfOptions &= ~dwfOptions;
dwRV = RasSetEntryProperties(lpszPhoneBook, (char*)lpszEntry, &entry,
sizeof(entry), NULL, 0);
}
return dwRV;
}
DWORD CRasClient::SetEntryServerProtocal(CString strEntry,
DWORD dwfNetProtocols, CString strPhoneBook /*=_T("")*/)
{
LPTSTR lpszEntry = strEntry.GetBuffer(1);
strEntry.ReleaseBuffer();
LPTSTR lpszPhoneBook = strPhoneBook.GetBuffer(1);
if(strPhoneBook == _T(""))
lpszPhoneBook = NULL;
strPhoneBook.ReleaseBuffer();
RASENTRY entry;
DWORD dwRV = GetEntryProperties(strEntry, &entry, lpszPhoneBook);
if(dwRV == 0)
{
entry.dwfNetProtocols = dwfNetProtocols;
dwRV = RasSetEntryProperties(lpszPhoneBook, (char*)lpszEntry, &entry,
sizeof(entry), NULL, 0);
}
return dwRV;
}
DWORD CRasClient::SetEntryIPAddress(CString strEntry, int nIPType,
BYTE a, BYTE b, BYTE c, BYTE d, CString strPhoneBook /*= _T("")*/)
{
LPTSTR lpszEntry = strEntry.GetBuffer(1);
strEntry.ReleaseBuffer();
LPTSTR lpszPhoneBook = strPhoneBook.GetBuffer(1);
if(strPhoneBook == _T(""))
lpszPhoneBook = NULL;
strPhoneBook.ReleaseBuffer();
RASENTRY entry;
DWORD dwRV = GetEntryProperties(strEntry, &entry, lpszPhoneBook);
if(dwRV == 0)
{
RASIPADDR ipDns;
ipDns.a = a;
ipDns.b = b;
ipDns.c = c;
ipDns.d = d;
switch(nIPType)
{
case IPADDRESS :
entry.dwfOptions |= RASEO_SpecificIpAddr;
entry.ipaddr = ipDns;
break;
case IPADDRESS_DNS:
entry.dwfOptions |= RASEO_SpecificNameServers;
entry.ipaddrDns = ipDns;
break;
case IPADDRESS_DNS_ALT:
entry.dwfOptions |= RASEO_SpecificNameServers;
entry.ipaddrDnsAlt = ipDns;
break;
case IPADDRESS_WINS:
entry.dwfOptions |= RASEO_SpecificNameServers;
entry.ipaddrWins = ipDns;
break;
case IPADDRESS_WINS_ALT:
entry.dwfOptions |= RASEO_SpecificNameServers;
entry.ipaddrWinsAlt = ipDns;
break;
}
dwRV = RasSetEntryProperties(lpszPhoneBook, (char*)lpszEntry, &entry,
sizeof(entry), NULL, 0);
}
return dwRV;
}
DWORD CRasClient::GetEntryProperties(CString strEntry, RASENTRY* lpRasEntry
, LPTSTR lpszPhoneBook)
{
LPTSTR lpszEntry = strEntry.GetBuffer(1);
strEntry.ReleaseBuffer();
if(RasValidateEntryName(lpszPhoneBook, lpszEntry) == ERROR_ALREADY_EXISTS)
{
BYTE bDeviceInfo = NULL;
DWORD dwDeviceInfoSize = sizeof(bDeviceInfo);
DWORD dwEntrySize = 0;
DWORD dwRV;
lpRasEntry->dwSize = sizeof(*lpRasEntry);
dwRV = RasGetEntryProperties(lpszPhoneBook, lpszEntry, lpRasEntry, &dwEntrySize,
&bDeviceInfo, &dwDeviceInfoSize); // GET 603
dwRV = RasGetEntryProperties(lpszPhoneBook, lpszEntry, lpRasEntry, &dwEntryS
Ras.rar_RAS 拨号
版权申诉
117 浏览量
2022-09-20
14:27:17
上传
评论
收藏 35KB RAR 举报
御道御小黑
- 粉丝: 61
- 资源: 1万+
最新资源
- delphi实现DBGrid全选和反选功能
- 25C11F41-2B2A-4D1A-AAA8-7C654526B129.pdf
- Android Studio Jellyfish(android-studio-2023.3.1.18-cros.deb)
- MVC+EF框架+EasyUI实现权限管理源码程序
- python第66-75天,Day66-75.rar
- python后端服务project-of-tornado.rar
- python测验,hello-tornado.rar
- 基于SpringBoot+Vue3快速开发平台、自研工作流引擎源码设计.zip
- docker安装部署全流程
- 基于树莓派的人脸识别系统python源码+项目部署说明+超详细代码注释.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0