?? rasclient.cpp
字號:
// RasClient.cpp
#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;
rasEntry.dwfOptions = RASEO_ModemLights;
// DON'T USE "RASDT_Modem", use "modem", otherwise dwRV = 87
strcpy(rasEntry.szDeviceType, strDeviceType);
strcpy(rasEntry.szDeviceName, strDeviceName);
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, &dwEntrySize,
&bDeviceInfo, &dwDeviceInfoSize); // GET 0
return dwRV;
}
else
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -