CRas ras; |
RASENTRY rasEntry; |
char strName[50]; // = "COMKK"; |
DWORD lpcb = 0; |
DWORD lpcDevices; |
RASDEVINFO* lpRasDevInfo; |
RASDEVINFO rasdevinfo; |
|
strcpy (strName,VPNName.GetBuffer(VPNName.GetLength())); |
RasEnumDevices(NULL, &lpcb, &lpcDevices); |
lpRasDevInfo = (LPRASDEVINFO) GlobalAlloc(GPTR, lpcb); |
lpRasDevInfo->dwSize = sizeof (RASDEVINFO); |
RasEnumDevices(lpRasDevInfo, &lpcb, &lpcDevices); |
strcpy (rasdevinfo.szDeviceName, lpRasDevInfo->szDeviceName); |
strcpy (rasdevinfo.szDeviceType, lpRasDevInfo->szDeviceType); |
rasEntry.dwSize = sizeof (RASENTRY); |
//rasEntry.dwfOptions = RASEO_RemoteDefaultGateway | RASEO_SpecificNameServers; |
//rasEntry.dwfOptions = RASEO_RequireMsEncryptedPw | RASEO_RequireDataEncryption; |
rasEntry.dwAlternateOffset = 0; |
rasEntry.dwCountryID = 86; |
rasEntry.dwCountryCode = 86; |
// rasEntry.dwDialExtraPercent = 75; |
// rasEntry.dwDialExtraSampleSeconds = 120; |
// rasEntry.dwDialMode = 1; |
// rasEntry.dwVpnStrategy = 1; |
// rasEntry.dwfNetProtocols = 4; |
rasEntry.dwfOptions = 1024262928; |
// rasEntry.dwfOptions2 = 367; |
rasEntry.dwFramingProtocol = 1; |
// rasEntry.dwHangUpExtraPercent = 10; |
// rasEntry.dwHangUpExtraSampleSeconds = 120; |
// rasEntry.dwRedialCount = 3; |
// rasEntry.dwRedialPause = 60; |
// rasEntry.dwType = RASET_VPN; |
rasEntry.dwFrameSize = 0; |
rasEntry.dwfNetProtocols = RASNP_Ip; // TCP/IP |
rasEntry.dwFramingProtocol = RASFP_Ppp; //PPP |
rasEntry.dwChannels = 0; |
rasEntry.dwReserved1 = 0; |
rasEntry.dwReserved2 = 0; |
// Strings |
strcpy (rasEntry.szAreaCode, " " ); |
strcpy (rasEntry.szScript, "" ); |
strcpy (rasEntry.szAutodialDll, "" ); |
strcpy (rasEntry.szAutodialFunc, "" ); |
strcpy (rasEntry.szX25PadType, "" ); |
strcpy (rasEntry.szX25Address, "" ); |
strcpy (rasEntry.szX25Facilities, "" ); |
strcpy (rasEntry.szX25UserData, "" ); |
strcpy (rasEntry.szDeviceName, "WAN 微型端口 (PPTP)" ); |
strcpy (rasEntry.szDeviceType, "vpn" ); |
strcpy (rasEntry.szLocalPhoneNumber, VPNAddress.GetBuffer(VPNAddress.GetLength())); /*"140.207.3.74"59.188.23.84"218.242.176.71"*/ //服务器地址或域名 |
// rasEntry.dwVpnStrategy = VS_DEFAULT; //vpn类型 |
// rasEntry.dwEncryptionType = ET_OPTIONAL; //数据加密类型 |
// IP addresses |
InitRASIP (rasEntry.ipaddr); |
InitRASIP (rasEntry.ipaddrDns); |
InitRASIP (rasEntry.ipaddrDnsAlt); |
InitRASIP (rasEntry.ipaddrWins); |
InitRASIP (rasEntry.ipaddrWinsAlt); |
//Create Entry |
DWORD dwError; |
|
dwError = ras.RasSetEntryProperties (NULL, strName, &rasEntry, sizeof (RASENTRY), NULL, NULL); |
if (dwError == 0) { |
RASDIALPARAMS dialParm; |
dialParm.dwSize = sizeof (RASDIALPARAMS); |
strcpy (dialParm.szEntryName, strName); |
strcpy (dialParm.szPhoneNumber, "" ); |
strcpy (dialParm.szCallbackNumber, "" ); |
strcpy (dialParm.szUserName,VPNUser.GetBuffer(VPNUser.GetLength())); // "zdx"/*"hdj"*/ |
strcpy (dialParm.szPassword,VPNPass.GetBuffer(VPNPass.GetLength())); // "19881011"/*"hdj"*/ |
strcpy (dialParm.szDomain, "" ); |
dwError = ras.RasSetEntryDialParams(NULL, &dialParm,FALSE); |
if ( dwError == 0 ) { |
//dwError = ras.RasSetCredentials(NULL, strName, &rasEntry, 0); |
m_log += "正在进行网络连接,请稍候...\r\n" ; |
frameWnd->PostMessage(WM_UPDATE_MESSAGE,0,0); |
//SetDlgItemText( IDC_EDIT_LOG, "正在进行网络连接,请稍候..." ); |
dwError = RasDial( NULL, NULL, &dialParm, 0L, NULL, &m_hRasConn ); |
if ( dwError ) { |
char szBuf[256] = "" ; |
// 网络连接错误 |
if ( RasGetErrorString( ( UINT )dwError, ( LPSTR )szBuf, 255 ) != 0 ) { |
_stprintf( ( LPTSTR )szBuf, "Undefined RAS Dial Error (%ld)." , dwError ); |
|
} |
|
m_log += "网络连接异常..." ; |
frameWnd->PostMessage(WM_UPDATE_MESSAGE,0,0); |
//SetDlgItemText( IDC_EDIT_LOG, szBuf ), |
EndDialog(FALSE); |
//return FALSE; |
} |
} |
} |
|
m_log += "远程网络已正常连接!\r\n" ; |
frameWnd->PostMessage(WM_UPDATE_MESSAGE,0,0); |