通过IWeb连接网络并下载一个图片文件,模拟器上测试成功,但在手机上测试引起死机,高手帮忙看看是什么问题。代码大概如下:
typedef struct _downloadfile {
AEEApplet a;
IFileMgr * m_pFileMgr;
IWeb * m_pIWeb;
ISource * m_pISource;
IImageCtl * m_pIImage;
AEECallback m_cbgps;
AEECallback m_cbimg;
AEECallback cb;
IWebResp * piWResp;
}downloadfile;
static void imgCallback(void * p)
{
int bytesRead;
char x[1000];
IImage* pSplash = NULL;
AEEImageInfo rImageInfo;
CtlAddItem ci;
AEERect rc;
downloadfile * pApp = (downloadfile *)p;
bytesRead = ISOURCE_Read(pApp->m_pISource, x, 1000);
while (bytesRead != ISOURCE_END && bytesRead != ISOURCE_ERROR) {
if (bytesRead != ISOURCE_WAIT)
IFILE_Write(file, x, bytesRead);
else {
ISOURCE_Readable(pApp->m_pISource, &pApp->m_cbimg);
return;
}
bytesRead = ISOURCE_Read(pApp->m_pISource, x, 1000);
}
IFILE_Release(file);
if(bytesRead != ISOURCE_ERROR)
{
if( (pSplash = ISHELL_LoadImage(pApp->a.m_pIShell,"map.png") ) != NULL)
{
IIMAGE_GetInfo(pSplash, &rImageInfo);
IDISPLAY_ClearScreen(pApp->a.m_pIDisplay);
MEMSET(&ci,0,sizeof(ci));
ci.pImage = pSplash;
rc.x = 0;
rc.y = 0;
rc.dx = 96;
rc.dy = 113;
IIMAGECTL_SetProperties(pApp->m_pIImage,CP_BORDER);
IIMAGECTL_SetRect(pApp->m_pIImage, &rc);
IIMAGECTL_SetImage(pApp->m_pIImage,pSplash);
IIMAGECTL_SetActive(pApp->m_pIImage,TRUE);
IIMAGECTL_Redraw(pApp->m_pIImage);
IIMAGE_Release(pSplash);
IDISPLAY_Update(pApp->a.m_pIDisplay);
return;
}
}
}
static void WebAction_GotResp(void *p)
{
downloadfile *pMe = (downloadfile *)p;
WebRespInfo *pwri;
pwri = IWEBRESP_GetInfo(pMe->piWResp);
pMe->m_pISource = pwri->pisMessage;
IFILEMGR_Remove(pMe->m_pFileMgr, "map.png");
file = IFILEMGR_OpenFile(pMe->m_pFileMgr, "map.png", _OFM_CREATE);
CALLBACK_Init(&pMe->m_cbimg,imgCallback,pMe);
ISOURCE_Readable(pMe->m_pISource, &pMe->m_cbimg);
}
static void WebAction_Start(downloadfile *pMe)
{
CALLBACK_Init(&pMe->cb, WebAction_GotResp, pMe);
IWEB_GetResponse(pMe->m_pIWeb,
(pMe->m_pIWeb, &pMe->piWResp, &pMe->cb, "http://image163.poco.cn/mypoco/myphoto/20100625/16/5548589320100625161506097.png",
WEBOPT_HANDLERDATA, pMe,
WEBOPT_METHOD, "GET ",
WEBOPT_END));
}
/*static void imgCallback(void * p)函数里定义了一个char x[1000],不清楚是否这个引起系统崩溃。在电脑的模拟器上,char x[1000]比char x[100]下载的速度快。这里要怎么定义才正确?
是否有朋友写过下载文件的简单代码?可否发上来借鉴一下?*/
------解决方案--------------------------------------------------------
到手机测试时,IP地址要用内网地址。