持续跟新中
1. 当使用容器定义指针类型的时候 要注意这个指针指向内容的变化
std::vector<char *> m_vPath;
char str[20] = "hello world";
int main()
{
for (int i = 0; i < 2; i++)
{
m_vPath.push_back(str);
strcpy(str,"123455");
}
}
上面本意是想将字符串
"hello world" 和
"123455"存入容器中 ,但是最后的结果是是"123455","123455" ,指针指向的内容已经发生变化
2.多线程问题:使用了公用 变量经常容易出错
在类中声明了一个类对象 m_ftp,,但是在线程函数DownLoad中对该对象进行了操作, 这样导致在主线程中如果在使用到的该对象的时候可能发生改变,使用的时候要考虑该值的变化对程序可有影响
void CFtpDownLoadDlg::DownLoadFile(CString LocalFoldPath,CString ServerFilePath,CString ServerFileName)
{
CString str;
str = LocalFoldPath;
if ( str.Right( 1 ) != "\\" )
str += "\\" + ServerFileName;
else
str += ServerFileName;
m_nCurUpFileSize = 0;
//计算远程文件大小
m_ftp.Size(( LPSTR )( LPCTSTR )ServerFilePath, &m_nCurUpFileSize, ftplib::image);
//设置下载信息回调
m_ftp.SetCallbackXferFunction( ( FtpCallbackXfer )CallbackXfer, this, 10240 );
int a = m_ftp.Get(( LPSTR )( LPCTSTR )str, ( LPSTR )( LPCTSTR )ServerFilePath, ftplib::image );
if ( a > 0 )
{
//BeginFindLocFile();
}
else
{
//MessageBox( _T( "文件下载失败,请检查是否登录!" ), _T( "提示" ), MB_ICONWARNING );
}
}