#include "StdAfx.h"
#include "resource.h"栀子花开
五要#include "RasDial.h"
const CString c_VPNServer = _T("127.0.0.1");
const CString c_VPNDescription = _T("vpn");
const CString c_VPNUrName = _T("vpnur");
const CString c_VPNPassword = _T("123456");
bool CreateVPN(const LPCTSTR pszEntryName, const LPCTSTR pszServerName,
const LPCTSTR pszUrName, const LPCTSTR pszPassWord)
{
RASENTRY rasEntry;
DWORD rasEntrySize, dwResult;
memt(&rasEntry, 0, sizeof(rasEntry));
rasEntrySize = sizeof(rasEntry);
rasEntry.dwCountryCode = 86;
rasEntry.dwCountryID = 86;
rasEntry.dwDialExtraPercent = 75;
rasEntry.dwDialExtraSampleSeconds = 120;
rasEntry.dwDialMode = RASEDM_DialAll;
rasEntry.dwType = RASET_Vpn;
rasEntry.dwRedialCount = 30;
rasEntry.dwRedialPau = 60;
rasEntry.dwSize = sizeof(rasEntry);
rasEntry.dwfOptions = RASEO_SwCompression | RASEO_RequireEncryptedPw | RASEO_RequireDataEncryption |
RASEO_PreviewUrPw;
rasEntry.dwFramingProtocol = RASFP_Ppp;
rasEntry.dwVpnStrategy = VS_PptpOnly;
rasEntry.dwfNetProtocols = RASNP_Ip;
rasEntry.dwEncryptionType = ET_Optional; //可选加密
rasEntry.dwHangUpExtraPercent = 10;
rasEntry.dwHangUpExtraSampleSeconds = 120;
lstrcpy(rasEntry.szLocalPhoneNumber, pszServerName);
lstrcpy(rasEntry.szDeviceType, RASDT_Vpn);
lstrcpy(rasEntry.szDeviceName, TEXT("vpn"));
dwResult = RasSetEntryProperties(NULL, pszEntryName, &rasEntry, sizeof(rasEntry), NULL, 0);
if (dwResult != 0)
{
AfxMessageBox(_T("error: SetEntryProperties"));
return fal;
}
RASDIALPARAMS rdParams;
ZeroMemory(&rdParams, sizeof(RASDIALPARAMS));
rdParams.dwSize = sizeof(RASDIALPARAMS);
lstrcpy(rdParams.szEntryName, pszEntryName);
lstrcpy(rdParams.szUrName, pszUrName);
lstrcpy(rdParams.szPassword, pszPassWord);
DWORD dwRet = RasSetEntryDialParams(NULL, &rdParams, TRUE);
/*
RASCREDENTIALS rc;
三水湾rc.dwSize = sizeof(RASCREDENTIALS);
rc.dwMask = 11;
lstrcpy(rc.szUrName, pszUrName);
lstrcpy(rc.szPassword, pszPassWord);
dwRet = RasSetCredentials(NULL, pszEntryName, &rc, FALSE);*/
if(dwRet == 0)
return true;
el
return fal;
}
bool ConnectVPN(void)
{
RASDIALPARAMS RasDialParams;
HRASCONN hRasConn;
DWORD Ret;就业帮扶
if (!CreateVPN(c_VPNDescription, c_VPNServer, c_VPNUrName, c_VPNPassword))
{
AfxMessageBox(_T("VPN创建失败"));
return fal;
}
RasDialParams.dwSize = sizeof(RASDIALPARAMS);
lstrcpy(RasDialParams.szEntryName, c_VPNDescription);生活中的数学手抄报内容
灵芝盆景lstrcpy(RasDialParams.szPhoneNumber, c_VPNServer);
lstrcpy(RasDialParams.szUrName, c_VPNUrName);
四月的冰河lstrcpy((LPSTR)RasDialParams.szPassword, _T("123456"));
//memcpy(RasDialParams.szPassword, c_VPNPassword, sizeof(c_VPNPassword));
if (sizeof("123456") == sizeof(c_VPNPassword))
{
OutputString("长度相等\n");
}
el
保密工作条例{
OutputString("长度不相等\n");
CString str;
str.Format(_T("charsize: %d \t %S \r\nstrsize: %d \t %s \r\n"), sizeof("123456"), c_VPNPassword, wcslen(c_VPNPassword), c_VPNPassword);
OutputDebugString(str);
}
OutputString("start connect. \n");
hRasConn = NULL;
Ret = RasDial(NULL, NULL, &RasDialParams, 0, &RasDialFunc, &hRasConn);
if (Ret != 0)
{
OutputString("RasDial %s failed with error %d\n", RasDialParams.szPhoneNumber, Ret);
RasDeleteEntry(NULL, RasDialParams.szEntryName);
return fal;
}
return true;
}
const CString c_VPNServer = _T("127.0.0.1");
const CString c_VPNDescription = _T("vpn");
const CString c_VPNUrName = _T("vpnur");
const CString c_VPNPassword = _T("123456");