我是
靠谱客的博主
留胡子魔镜,最近开发中收集的这篇文章主要介绍
WinCE 下 RAS 拨号连接的建立和拨号过程,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
在 CE 下如果系统没有建立拨号网络,要实现上网功能时,就需要通过代码来实现建立拨号网络、拨号实现上网的过程。
以下代码中的参数和拨号所用数值,都是电信 EVDO 的配置。如果换 GSM 或 WCDMA 时,请相应修改。
- HRASCONN ghRasConn = NULL;
-
-
-
- BOOL CTCPClientDlg::SetDevCfg(TCHAR *ptcRasEntryName)
- {
- HKEY hk;
- unsigned char cDevCfg[684];
- TCHAR tcRegAddr[512 + 1];
- DWORD *pdwEapConnData = NULL;
-
- ZeroMemory(tcRegAddr,sizeof(TCHAR) * (512 + 1));
- ZeroMemory(cDevCfg,sizeof(char) * 683);
- cDevCfg[0] = 0x30;
- cDevCfg[4] = 0x05;
- cDevCfg[9] = 0x01;
- cDevCfg[13] = 0xC2;
- cDevCfg[14] = 0x01;
- cDevCfg[18] = 0x08;
-
- wsprintf(tcRegAddr,L"Comm\RasBook\%s",ptcRasEntryName);
-
- if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER,tcRegAddr,0,0,&hk))
- {
- RegSetValueEx(hk,L"DevCfg",0,REG_BINARY,(LPBYTE)cDevCfg,sizeof(cDevCfg));
- RegSetValueEx(hk,L"EapConnData",0,REG_BINARY,(LPBYTE)pdwEapConnData,0);
- RegFlushKey(HKEY_CURRENT_USER);
-
- RegCloseKey(hk);
-
- return TRUE;
- }
- return FALSE;
- }
-
- BOOL CTCPClientDlg::CreateRASLink(TCHAR *ptcRasEntryName,TCHAR *ptcModemName)
- {
- LPRASENTRY lpRasEntry = NULL;
- DWORD dwRasEntrySize = sizeof(RASENTRY);
- DWORD dwBufferSize = 0;
- DWORD dwRet = 0;
- BOOL bRet = TRUE;
-
- if(NULL == ptcRasEntryName || NULL == ptcModemName)
- return FALSE;
-
- RasGetEntryProperties(NULL,L"",NULL,&dwBufferSize,NULL,NULL);
- if(0 == dwBufferSize)
- return FALSE;
-
- lpRasEntry = (LPRASENTRY)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,dwBufferSize);
- if(NULL == lpRasEntry)
- return FALSE;
-
- ZeroMemory(lpRasEntry,sizeof(RASENTRY));
- lpRasEntry->dwSize = dwBufferSize;
- lpRasEntry->dwfOptions = RASEO_RemoteDefaultGateway;
-
-
- lpRasEntry->dwCountryCode = 86;
- lstrcpy(lpRasEntry->szAreaCode,L"10");
- lstrcpy(lpRasEntry->szLocalPhoneNumber,L"#777");
-
- lstrcpy(lpRasEntry->szDeviceType,RASDT_Modem);
- lstrcpy(lpRasEntry->szDeviceName,ptcModemName);
- lpRasEntry->dwfNetProtocols = RASNP_Ip;
- lpRasEntry->dwFramingProtocol = RASFP_Ppp;
-
- dwRet = RasSetEntryProperties(NULL,ptcRasEntryName,lpRasEntry,dwBufferSize,NULL,0);
- if(0 != dwRet)
- {
- bRet = FALSE;
- }
- HeapFree(GetProcessHeap(),0,(LPVOID)lpRasEntry);
-
- return bRet;
- }
-
- BOOL CTCPClientDlg::NetworkDialAndParams(TCHAR *ptcRasEntryName)
- {
- DWORD dwRet = 0;
- UINT i = 0;
- RASDIALPARAMS rdParams;
-
- ZeroMemory(&rdParams, sizeof(RASDIALPARAMS));
-
- rdParams.dwSize = sizeof(RASDIALPARAMS);
- wcscpy(rdParams.szEntryName,ptcRasEntryName);
-
- wcscpy(rdParams.szUserName,L"card");
- wcscpy(rdParams.szPassword,L"card");
-
- ghRasConn = NULL;
- dwRet = RasDial(NULL,NULL,&rdParams,0xFFFFFFFF,NULL,&ghRasConn);
- if(0 != dwRet)
- {
- RETAILMSG(1,(L"RasDial Error: %d.rn",dwRet));
- return FALSE;
- }
- return TRUE;
- }
调用示例:
- void CNetworkDialDlg::OnBtnClickedOpenNet()
- {
- GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);
- m_NetName.EnableWindow(FALSE);
-
-
- if(CreateRASLink(RASDIAL_NET_NAME,RASDIAL_NET_MODEM_NAME))
- {
- if(SetDevCfg(RASDIAL_NET_NAME))
- {
- if(NetworkDialAndParams(RASDIAL_NET_NAME,ghMainWnd))
- {
- RETAILMSG(1,(L"[TCP Client]Dial new work success.rn"));
-
- SetTimer(RASDIAL_NETSHOW_TIMER_ID,RASDIAL_NETSHOW_TIME_OUT,NULL);
- }
- else
- {
- RETAILMSG(1,(L"[TCP Client]Dial new work failed!rn"));
- }
- }
- else
- {
- RETAILMSG(1,(L"[TCP Client]Set RAS device config failed!rn"));
- }
- }
- else
- {
- RETAILMSG(1,(L"[TCP Client]Create RAS link failed!rn"));
- }
- }
-
- BOOL CNetworkDialDlg::PreTranslateMessage(MSG* pMsg)
- {
- switch(pMsg->message)
- {
- case WM_RASDIALEVENT:
- OnRasDialEvent(pMsg->wParam,pMsg->lParam);
- break;
- case WM_USER + 0x1000:
- if(1 == pMsg->wParam)
- {
- GetDlgItem(IDC_STATIC_PING_STATUS)->SetWindowText(L"PING 状态: 成功");
- }
- else
- {
- GetDlgItem(IDC_STATIC_PING_STATUS)->SetWindowText(L"PING 状态: 失败");
- }
- break;
- default:
- break;
- }
-
- return CDialog::PreTranslateMessage(pMsg);
- }
-
-
-
-
-
-
-
-
-
-
-
-
- LRESULT CNetworkDialDlg::OnRasDialEvent(WPARAM wParam,LPARAM lParam)
- {
- RASCONNSTATE RasState = (RASCONNSTATE)wParam;
- DWORD dwError = (DWORD)lParam;
-
- gRasState = RasState;
- switch(RasState)
- {
- case RASCS_OpenPort:
- RETAILMSG(1,(L"[TCP Ras Event]1.RasState: Open portrn"));
- break;
-
- case RASCS_PortOpened:
- RETAILMSG(1,(L"[TCP Ras Event]2.RasState: Port openedrn"));
- break;
-
- case RASCS_DeviceConnected:
- {
-
- RETAILMSG(1,(L"[TCP Ras Event]3.RasState: Device Connectedrn"));
- }
- break;
-
- case RASCS_AllDevicesConnected:
-
- RETAILMSG(1,(L"[TCP Ras Event]4.RasState: All Device Connectedrn"));
- break;
-
- case RASCS_Authenticate:
- {
-
- RETAILMSG(1,(L"[TCP Ras Event]5.Authenticatingrn"));
- }
- break;
-
- case RASCS_Authenticated:
- {
-
- RETAILMSG(1,(L"[TCP Ras Event]6.Authenticated, continue login...rn"));
- }
- break;
-
- case RASCS_AuthNotify:
- {
- RETAILMSG(1,(L"[TCP Ras Event]RASCS_AuthNofify received,Error: %drn",dwError));
- switch(dwError)
- {
- case ERROR_RESTRICTED_LOGON_HOURS:
- case ERROR_ACCT_DISABLED:
- case ERROR_PASSWD_EXPIRED:
- case ERROR_NO_DIALIN_PERMISSION:
- case ERROR_CHANGING_PASSWORD:
- default:
- break;
- }
- }
- break;
-
- case RASCS_Connected:
- {
- RETAILMSG(1,(L"[TCP Ras Event]7.RASCS_Connected receivedrn"));
- gbNetConnected = TRUE;
- }
- break;
-
- case RASCS_Disconnected:
- {
- CString csError;
- RETAILMSG(1,(L"[TCP Ras Event]8.RASCS_Disconnected received. Error: %drn",dwError));
-
- csError.Format(L"建立网络出现错误:%d",dwError);
- GetDlgItem(IDC_BUTTON1)->EnableWindow(TRUE);
- m_NetName.EnableWindow(TRUE);
- giRasDialTimerCount = 0;
- GetDlgItem(IDC_STATIC_STATUS)->SetWindowText(csError);
- KillTimer(RASDIAL_NETSHOW_TIMER_ID);
- }
- break;
-
- default:
- RETAILMSG(1,(L"[TCP Ras Event]9.RAS Other RasState:%drn", RasState));
- break;
- }
-
- return TRUE;
- }
//================================
备注::
1、可以参考WINCE下自带的拨号程序----Rnaapp.exe/RasDial.exe-----真正拨号的程序,被connmc.exe(网络跟连接管理)程序调起来。另外WINCE自带的拨号连接是有源码的,位置在PUBLICCOMMONOAKDRIVERSNETSAMPCONNMC。
2、确实不错的东西,这样就不用每次去手动建立连接并去一个个参数设置了!
from:
http://blog.csdn.net/91program/article/details/8262374
http://blog.csdn.net/xqhrs232/article/details/8555969
最后
以上就是留胡子魔镜为你收集整理的WinCE 下 RAS 拨号连接的建立和拨号过程的全部内容,希望文章能够帮你解决WinCE 下 RAS 拨号连接的建立和拨号过程所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复