程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ftp-MFC多線程,與FTP連接

ftp-MFC多線程,與FTP連接

編輯:編程綜合問答
MFC多線程,與FTP連接

圖片說明

問題貌似出現在 AfxBeginThread(mtQuery, pParam, THREAD_PRIORITY_NORMAL, 0,NULL);
這一行代碼中。函數 mtQuery 如下。
為什麼會出現上面圖片那一行的錯誤。。

#ifndef MT_H

#define MT_H

#include "stdafx.h"
#include "afxinet.h"

typedef struct PARAM{
CListBox * pListBox;
CString strFtp;
CString strUCount;
CString strUPwd;
}*PPARAM;

UINT _cdecl mtQuery(LPVOID pParam)
{
PPARAM pparam = (PPARAM)pParam;
CListBox * pListBox = pparam->pListBox;

CString strFtp = pparam->strFtp;
CString strUCount = pparam->strUCount;
CString strUPwd = pparam->strUPwd;


CInternetSession * pSession = new CInternetSession(NULL, 1, PRE_CONFIG_INTERNET_ACCESS);
CFtpConnection * pFtpConnection;
try{
    pFtpConnection = pSession->GetFtpConnection(strFtp, strUCount, strUPwd, 21, TRUE);
}
catch (CInternetException* pEx){
    TCHAR error[1024] = { 0 };
    pEx->GetErrorMessage(error, 1024);
    AfxMessageBox(error);
    pEx->Delete();
    pFtpConnection = NULL;
}
if (pFtpConnection != NULL)
{

    CFtpFileFind * pFileFind = new CFtpFileFind(pFtpConnection);

    if (pFileFind != NULL)
    {
        BOOL bContinue = pFileFind->FindFile(L"*");
        if (!bContinue)
        {
            pFileFind->Close();
            pFileFind = NULL;
        }
        while (bContinue)
        {
            bContinue = pFileFind->FindNextFile();
            CString strFileName = pFileFind->GetFileName();
            if (pFileFind->IsDirectory())
            {
                strFileName = L"[" + strFileName + L"]";
            }
            pparam->pListBox->AddString(strFileName);
        }

        if (pFileFind != NULL)
        {
            pFileFind->Close();
            pFileFind = NULL;
        }
        delete pFileFind;
    }
    if (pFtpConnection!=NULL)
    {
        pFtpConnection->Close();
        delete pFtpConnection;
    }

    if (pSession!=NULL)
    {
        pSession->Close();
        delete pSession;
    }
}
return 0;

}

#endif

最佳回答:


好的。問題已經找到了。。由於調用AfxBeginThread之後,主線程把這個線程的參數個delete掉了。。才開始多線程,,意識不夠到位啊~~~

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved