我的代码里面,需要从远程FTP服务器下载大量到本地,然后载入到容器里面,然后到视图区显示,在我的一个消息相应函数里面,先初始化一些东西,然后开辟一条线程去下载图片,然后发送自定义消息刷新显示试图区,没下载10幅图就刷新一次,但我的线程函数里面的FTP下载函数执行有问题,可以创建本地图片存放目录,但就是下载图片除问题,代码如下,请大家帮我分析分析,谢谢!!
UpdateData(TRUE);
............
............ //初始化FTP连接
m_pInetSession = new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
m_pFtpConnection = m_pInetSession->GetFtpConnection(m_server,m_user,m_password,21,TRUE);
DownLoadYXTX();////下载几个小图表 hThread = CreateThread(NULL,0,
(LPTHREAD_START_ROUTINE)FunProc1,
(LPVOID)m_pFtpConnection,
0,
&ThreadID);  /////创建线程下载图片
    
GetPSTX(m_pFtpConnection);/////下载另一类型的图片
当我把GetPSTX()和创建线程代码交换位置之后,就可以正常运行,FunProc1可以下载图片,像现在这样顺序放,FunProc1只能创建目录不能下载,GetPSTX都能执行,如果把GetPSTX()里面的功能放线程函数里面,同样也只能创建目录,不能下载.........
........////线程函数如下
void FunProc1(LPVOID lpParameter)
{
  ////下载滚扫图像
   CFtpConnection *m_pFtpConnection;
   m_pFtpConnection = (CFtpConnection*)lpParameter;
   CString strPath =  "C:\\Program Files\\CISS_NET\\bmp\\";
if(!SetCurrentDirectory(strPath))
{
CreateDirectory(strPath,NULL);
}
strPath += "龙深1井湿\\";
if (!SetCurrentDirectory(strPath))
{
CreateDirectory(strPath,NULL);
}
strPath += "第17回次\\";
if (!SetCurrentDirectory(strPath))
{
CreateDirectory(strPath,NULL);
}
strPath = strPath + "缩略图像\\" ; 
if(!SetCurrentDirectory(strPath))
{
CreateDirectory(strPath,NULL);
}
strPath = strPath + "滚扫图像\\" ; 
if(!SetCurrentDirectory(strPath))
{
CreateDirectory(strPath,NULL);
}

CString  strRemotedir = "龙深1井湿/第17回次/缩略图像/滚扫图像/";
         开始遍历下载
   CFtpFileFind finder(m_pFtpConnection);
   BOOL bWorking = finder.FindFile(strRemotedir+"*.*");
   CString str;
   while (bWorking)
   {
   bWorking = finder.FindNextFile();
   str = finder.GetFileName();
   m_pFtpConnection->GetFile(strRemotedir+str,strPath+str,TRUE);    
   }
}
请各位告诉帮帮忙,现在暂时分不够了,问题解决了,一定补上,保证至少100分,谢谢,感激不尽啊!!

解决方案 »

  1.   

    看LZ描述的现象应该是m_pFtpConnection不支持多线程的原因吧。修改下:
    在FunProc1线程函数中使用新的CInternetSession及新的FtpConnection。和主线程不影响就可以了。
      

  2.   


    但是我在线程函数里面,定义CInternetSession和CFtpConnection对象,编译都通不过啊CInternetSession *m_pInetSession ;
    CFtpConnection *m_pFtpConnection ;
    m_pInetSession = new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
     m_pFtpConnection = m_pInetSession->GetFtpConnection(m_server,m_user,m_password,21,TRUE);??????