急,GPRS联网问题?

xw1980xw 2006-07-28 05:20:14
我在开发smartphone的应用要用到socket连接,但是我要先联一下IE和移动梦网,后才能联通,我想在程序中直接联GPRS,有没有人知道怎么做
CONNMGR_CONNECTIONINFO ConnInfo;
ZeroMemory(&ConnInfo, sizeof(ConnInfo));
ConnInfo.cbSize = sizeof(ConnInfo);
ConnInfo.dwParams = CONNMGR_PARAM_GUIDDESTNET;
ConnInfo.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE;
ConnInfo.guidDestNet = DestInfo.guid;
ConnInfo.dwFlags = CONNMGR_FLAG_PROXY_WAP;
hResult = ConnMgrEstablishConnection(&ConnInfo, &pNet->hConnection);
我用这样联网,可是不行,我去掉这段代码,只要先联IE(出现G的图标后),一样可以联网了,
怎么会这样!
...全文
487 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xw1980xw 2006-07-31
  • 打赏
  • 举报
回复
我还有几个问题 在你给的代码中
CONNMGRCONNECTIONSTATUS
CONNMGRESTABLISHCONNECTION
不能识别,我是在eVC 下smartphone开发,还有如果我要用wap代理来上cmnet的话要怎么做?
xw1980xw 2006-07-29
  • 打赏
  • 举报
回复
太感谢了!
cuterain 2006-07-29
  • 打赏
  • 举报
回复
///////////////////////////////////////////////////////////////////////
//funciton:EstablishDatacall
//establish connection with web
//Output: IP code
//return value: BOOL
//////////////////////////////////////////////////////////////////////
BOOL EstablishDatacall(TCHAR *IPout)
{
CHAR szHostname[255];
TCHAR IP[17];
HOSTENT *pHostEnt=NULL;
int nAdapter = 0;
IN_ADDR *tsim=NULL;
BOOL tried2Connect=FALSE;

IP[0]=0; // Clear the IP Address
if (IPout!=NULL) IPout[0]=0;
tryagain:
nAdapter=0;
gethostname( szHostname, sizeof( szHostname ));
pHostEnt = gethostbyname( szHostname );
while ( pHostEnt!=NULL && pHostEnt->h_addr_list[nAdapter] )
{
// in case a device has multiple ethernet cards
// i.e. 802.11, Bluetooth, USB-Cradle
// we need to go though all pHostEnt->h_addr_list[nAdapter]
tsim=(IN_ADDR *)pHostEnt->h_addr_list[nAdapter];
if (tsim->S_un.S_un_b.s_b1==192 ||
tsim->S_un.S_un_b.s_b1==169 ||
tsim->S_un.S_un_b.s_b1==127 ||
tsim->S_un.S_un_b.s_b1==255)
// If you want to make sure you have a real Internet
// connection you cannot bet on IpAddresses starting with
// 127 and 255. 192 and 169 are local IP addresses and
// might be routed or proxied
nAdapter++;
else
{
wsprintf(IP,TEXT("%d.%d.%d.%d"),
tsim->S_un.S_un_b.s_b1,
tsim->S_un.S_un_b.s_b2,
tsim->S_un.S_un_b.s_b3,
tsim->S_un.S_un_b.s_b4);
if (IPout!=NULL)
wsprintf(IPout,IP);
break;
}
}

// the next lines only work with Pocket PC Phone
// and Smartphone
#if (WIN32_PLATFORM_PSPC>300 || WIN32_PLATFORM_WFSP )
// Pocket PC Phone Edition has set WIN32_PLATFORM_PSPC to 310
if (IP[0]==0 && tried2Connect==FALSE)
{
CONNMGRCONNECTIONSTATUS hConnMgrConnectionStatus = NULL;
CONNMGRESTABLISHCONNECTION hConnMgrEstablishConnectionSync=NULL;
// It is good practice to load the cellcore.dll
// dynamically to be able to compile the code even for
// older platforms
HINSTANCE hcellDll = LoadLibrary(TEXT("cellcore.dll"));
if (hcellDll)
{
// We need the Status and a call to establish the
// connection
hConnMgrConnectionStatus =(CONNMGRCONNECTIONSTATUS)GetProcAddress(hcellDll,TEXT("ConnMgrConnectionStatus"));
// The next line is just for debugging. You will have
// to decide what you want to do if this call fails
DWORD a=GetLastError();
hConnMgrEstablishConnectionSync =(CONNMGRESTABLISHCONNECTION)GetProcAddress(hcellDll,TEXT("ConnMgrEstablishConnectionSync"));
a=GetLastError();

// Here comes the main code:
// First we check if we might have a connection
DWORD pdwStatus;
(* hConnMgrConnectionStatus)(&g_phWebConnection,&pdwStatus);
if (pdwStatus==CONNMGR_STATUS_CONNECTED)
{
//We are already connected!
//This code should never run since we should
//have a valid IP already.
//If you still get here, you probably have
//stale connection.
}
else
{
//We are not connected, so lets try:
//The CONNECTIONINFO is the structure that
//tells Connection Manager how we want
//to connect
CONNMGR_CONNECTIONINFO sConInfo;
memset(&sConInfo,0, sizeof(CONNMGR_CONNECTIONINFO));
sConInfo.cbSize=sizeof(CONNMGR_CONNECTIONINFO);
// We want to use the “guidDestNet” parameter
sConInfo.dwParams=CONNMGR_PARAM_GUIDDESTNET;
// This is the highest data priority.
sConInfo.dwPriority=CONNMGR_PRIORITY_USERINTERACTIVE;
sConInfo.dwFlags=0;
// Lets be nice and share the connection with
// other applications
sConInfo.bExclusive=FALSE;
sConInfo.bDisabled=FALSE;
sConInfo.guidDestNet=IID_DestNetInternet;

// We want to wait until the connection was
// established successful but not longer then
// 60 seconds. You can use
// ConnMgrEstablishConnection to establish
// an asynchronous connection.
if ((*hConnMgrEstablishConnectionSync)(&sConInfo,&g_phWebConnection,60000,&pdwStatus)==S_OK)
{
//We are successfully connected!
//Now lets try to get the new IP address…

tried2Connect=TRUE;
goto tryagain;
}
else
{
tried2Connect=FALSE;
//Doh! Connection failed!
}
}
}
}
#endif
return tried2Connect;
}


然后可以用URLDownloadToFile来下载文件

最后要用

//close connect
CONNMGRRELEASECONNECTION g_hConnMgrReleaseConnection=NULL;
HINSTANCE hcellDll = LoadLibrary(TEXT("cellcore.dll"));

if (hcellDll)
{
//release connection
g_hConnMgrReleaseConnection =(CONNMGRRELEASECONNECTION)GetProcAddress(hcellDll,TEXT("ConnMgrReleaseConnection"));
(*g_hConnMgrReleaseConnection)(g_phWebConnection, 1);
}

来关闭连接


在smartphone 2003 上测试通过。

7,655

社区成员

发帖
与我相关
我的任务
社区描述
Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox LIVE游戏、Zune音乐与独特的视频体验整合至手机中。
社区管理员
  • Windows客户端开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧