在MFC中写了个线程,用来传输文件的。
UINT ThreadFunc(LPVOID lpParam)
{ threadInfo* pInfo=(threadInfo*)lpParam; CFTPUploaderApp *app = (CFTPUploaderApp *)AfxGetApp();
app->IsThreadRunning=true;
CString sFileName;
int returnNum;
char *userName = new char[50];
memset(userName,NULL,50);
memcpy(userName,app->user,strlen(app->user));
FtpClient* client = new FtpClient("172.28.16.147",21); client->setCommand("USER ",userName);
client->sendCommand();
returnNum = client->receiveCommand();
if(returnNum == 331)
{
client->setCommand("PASS ",app->inputpassword.GetBuffer());
client->sendCommand();
returnNum = client->receiveCommand(); if(returnNum == 230)
{
char* filename = new char[512];
memset(filename,NULL,512); client->setCommand("PASV");
client->sendCommand();
client->receiveCommand();
client->getPort();
client->setCommand("TYPE ","I");
client->sendCommand();
client->receiveCommand();
client->interlizeDataSocket();
//----------循环遍历list.dat文件上传开始----------// while(true)
{
CString tmp,first;
CStdioFile file("list.dat",CFile::modeReadWrite);
file.ReadString(tmp);
if(tmp=="")
break;
first=tmp;
CString str="";
while(file.ReadString(tmp)&&tmp!="")
{
str+=tmp;
}
file.SetLength(0);
file.WriteString(str);
file.Close();
char fileName[100]="",url[100]="",size[10]="";
sscanf(first,"%s %s %s",fileName,url,size);
if((LONGLONG)size!=0)
{
client->setCommand("REST",size);
client->sendCommand();
client->receiveCommand();
} client->setCommand("STOR ",UTF8Convert(fileName,936,CP_UTF8).GetBuffer());
client->sendCommand();
client->receiveCommand();
client->sendData(url,pInfo->pctrlProgress,(LONGLONG)size);
client->receiveCommand(); //想在此处执行完再进行下一次的循环,可是现实是程序还没执行完这个函数就开始下一个循环了,何解??? }
//----------循环遍历list.dat文件上传结束----------//
}
}
app->IsThreadRunning=false;
return 1;
}
UINT ThreadFunc(LPVOID lpParam)
{ threadInfo* pInfo=(threadInfo*)lpParam; CFTPUploaderApp *app = (CFTPUploaderApp *)AfxGetApp();
app->IsThreadRunning=true;
CString sFileName;
int returnNum;
char *userName = new char[50];
memset(userName,NULL,50);
memcpy(userName,app->user,strlen(app->user));
FtpClient* client = new FtpClient("172.28.16.147",21); client->setCommand("USER ",userName);
client->sendCommand();
returnNum = client->receiveCommand();
if(returnNum == 331)
{
client->setCommand("PASS ",app->inputpassword.GetBuffer());
client->sendCommand();
returnNum = client->receiveCommand(); if(returnNum == 230)
{
char* filename = new char[512];
memset(filename,NULL,512); client->setCommand("PASV");
client->sendCommand();
client->receiveCommand();
client->getPort();
client->setCommand("TYPE ","I");
client->sendCommand();
client->receiveCommand();
client->interlizeDataSocket();
//----------循环遍历list.dat文件上传开始----------// while(true)
{
CString tmp,first;
CStdioFile file("list.dat",CFile::modeReadWrite);
file.ReadString(tmp);
if(tmp=="")
break;
first=tmp;
CString str="";
while(file.ReadString(tmp)&&tmp!="")
{
str+=tmp;
}
file.SetLength(0);
file.WriteString(str);
file.Close();
char fileName[100]="",url[100]="",size[10]="";
sscanf(first,"%s %s %s",fileName,url,size);
if((LONGLONG)size!=0)
{
client->setCommand("REST",size);
client->sendCommand();
client->receiveCommand();
} client->setCommand("STOR ",UTF8Convert(fileName,936,CP_UTF8).GetBuffer());
client->sendCommand();
client->receiveCommand();
client->sendData(url,pInfo->pctrlProgress,(LONGLONG)size);
client->receiveCommand(); //想在此处执行完再进行下一次的循环,可是现实是程序还没执行完这个函数就开始下一个循环了,何解??? }
//----------循环遍历list.dat文件上传结束----------//
}
}
app->IsThreadRunning=false;
return 1;
}
解决方案 »
- VC6.0的程序没错误但是debug中的exe提示如下的错误不能运行
- 关于CreateRemoteThread的问题
- 请问如何在一个进程中打开多个console窗口?
- 如何定义自己的API类?
- 如何把TC写的图形代码运行结果,屏幕图形保存在WORD文档中?
- 如何向窗口发送组合键
- the application was unable to start correctly(0xc0150002)
- 两个问题:关于CEdit和CListCtrl
- 关于窗口及框架窗口中视图的析构?
- 263要收费了
- 在VC6.0下面做了一个对话框应用程序,实现图片的转换和显示,但是运行后出现“testftsdll2 Microsoft基础类应用程序已停止工作”
- 打开IE在什么时候能获取到地址栏地址
你想要同步?可以线程里WaitForSingleObject某一事件对象,其它线程里,比如主线程里满足某一条件的时候SetEvent。线程函数WaitFor函数返回,接着往下执行