|
RASENTRY rasEntry;
DWORD dw;
RASDIALPARAMS rdParams;//拨号参数
BOOL flag;
//初始化拨号参数
memset (&rasEntry, 0, sizeof(RASENTRY));
rdParams.dwSize=sizeof(RASDIALPARAMSW);
rasEntry.dwSize = sizeof (RASENTRY);
rasEntry.dwfOptions = 4194304;
rasEntry.dwCountryCode = 86;//china
rasEntry.dwfNetProtocols = RASNP_Ip; // TCP/IP
rasEntry.dwFramingProtocol = RASFP_Ppp; //PPP
CString aa;
wcscpy (rasEntry.szAreaCode, L"10");
wcscpy (rasEntry.szLocalPhoneNumber, L"*99#");
wcscpy(rasEntry.szDeviceType,RASDT_Modem);
wcscpy(rasEntry.szDeviceName,TEXT("GPRS modem"));
wcscpy(rdParams.szEntryName,L"GPRST");
wcscpy(rdParams.szPhoneNumber,L"*99***1#");
RasSetEntryDialParams(NULL,&rdParams,true);
DWORD dwRet;
//拨号连接
byte lpb[512] ;
memset(lpb,0,sizeof(lpb));
lpb[0] = 180;
lpb[1] = 1;
lpb[4] = 180;
lpb[5] = 1;
lpb[8] = 180;
lpb[9] = 1;
lpb[12] = 1;
lpb[16] = 15;
lpb[20] = 1;
lpb[24] = 2;
lpb[76] = 1;
lpb[80] = 2;
lpb[84] = 2;
TCHAR apn[] = L"cmnet";
for (int i = 0, step = 0; i < wcslen(apn); i++, step += 2)
{
*(lpb + 88 + step)=(BYTE)*(apn+i);
}
lpb[344] = 1;
lpb[348] = 1;
if(!RasSetEntryProperties(NULL,L"GPRST",&rasEntry,sizeof(RASENTRY),lpb,sizeof(lpb)))
AfxMessageBox(L"Set ok!");
else
AfxMessageBox(L"Set failed!");
RasSetEntryDialParams (NULL, &rdParams, FALSE);
dwRet = RasDial(NULL,NULL,&rdParams,0xFFFFFFFF,m_hWnd ,&hRasConn);
if(dwRet != 0)//connection successful
{
AfxMessageBox(L"Connected failed!");
CString ss;
ss.Format(L"%d",dwRet);
AfxMessageBox(ss);
RasHangUp(hRasConn);
}
else
{
AfxMessageBox(L"OK!");
}
|
|