wince6.0利用ras实现自己控制3g网络的连接
最近一直在调拨号连接,在网上查了很多资料,也查了msdn,msdn上面有个示例的程序,根据那个程序,自己做了一个拨号连接的小面板,自己控制网络的连接,不再需要用控制面板里的拨号连接了

以下是我用vs的mfc程序的源码,有兴趣的可以看一下,仅供参考
// rasDlg.cpp : implementation file
//
//
// 原创: goneman
// 修改时间:2010.5.23
// 作用: 通过点击连接和断开按钮实现3g网络的连接与断开
//
//
#include "stdafx.h"
#include "ras.h"
#include "rasDlg.h"
#include <ras.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
HRASCONN hRasConn = NULL;
// CrasDlg dialog
CrasDlg::CrasDlg(CWnd* pParent /*=NULL*/)
: CDialog(CrasDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CrasDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CrasDlg, CDialog)
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
ON_WM_SIZE()
#endif
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON1, &CrasDlg::OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, &CrasDlg::OnBnClickedButton2)
END_MESSAGE_MAP()
// CrasDlg message handlers
BOOL CrasDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CrasDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
if (AfxIsDRAEnabled())
{
DRA::RelayoutDialog(
AfxGetResourceHandle(),
this->m_hWnd,
DRA::GetDisplayMode() != DRA::Portrait ?
MAKEINTRESOURCE(IDD_RAS_DIALOG_WIDE) :
MAKEINTRESOURCE(IDD_RAS_DIALOG));
}
}
#endif
void CrasDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
RASDIALPARAMS RasDialParams;
// Set hRasConn to NULL before attempting to connect.
// Initialize the structure.
memset (&RasDialParams, 0, sizeof (RASDIALPARAMS));
CString szRasEntryName, szUserName, szPassword, szDomain,szPhoneNumber;
szRasEntryName ="CDMA";
szUserName = "";
szPassword = "vnet.mobi";
szDomain = "";
szPhoneNumber="#777";
// Configure the RASDIALPARAMS structure.
RasDialParams.dwSize = sizeof (RASDIALPARAMS);
RasDialParams.szPhoneNumber[0] = TEXT('\0');
RasDialParams.szCallbackNumber[0] = TEXT('\0');
wcscpy (RasDialParams.szEntryName, szRasEntryName);
wcscpy (RasDialParams.szUserName, szUserName); //This is optional wcscpy (RasDialParams.szPassword, szPassword); //This is optional
wcscpy (RasDialParams.szPassword, szPassword);
wcscpy (RasDialParams.szPhoneNumber, szPhoneNumber);
wcscpy (RasDialParams.szDomain, szDomain); //This is optional
/*}*/
// Try to establish RAS connection.
if (RasDial (NULL, // Extension not supported
NULL, // Phone book is in registry
&RasDialParams, // RAS configuration for connection
0xFFFFFFFF, // Notifier type is a window handle
NULL, // Window receives notification message
&hRasConn) != 0) // Connection handle
{
;
MessageBox (TEXT("Could not connect using RAS"));
}
else
{
//str=
MessageBox(TEXT("connect is successed"));
}
}
void CrasDlg::OnBnClickedButton2()
{
// TODO: Add your control notification handler code here
if(RasHangUp(hRasConn)!=0)
{
MessageBox(TEXT("disconnect is failed"));
}
else
{
MessageBox(TEXT("disconnect is successed"));
}
}
浙公网安备 33010602011771号