CFtpConnection::OpenFile
CInternetFile* OpenFile( LPCTSTR pstrFileName, DWORD dwAccess = GENERIC_READ, DWORD dwFlags = FTP_TRANSFER_TYPE_BINARY, DWORD dwContext = 1 );Return ValueA pointer to a CInternetFile object.请问:OpenFile函数返回的指针CinternetFile*用完的时候需要调用CInternetFile::close么?
CInternetFIle*指针需要释放么?

解决方案 »

  1.   

    Close是需要调用的。
    指针也需要delete来释放。
    看内容函数实现
    .....
    CInternetFile* pFile = new CInternetFile(hFile, pstrFileName, this,
    (dwAccess == GENERIC_READ));
    return pFile;
      

  2.   

    Close是需要调用的。
    指针也需要delete来释放。
    看内容函数实现
    .....
    CInternetFile* pFile = new CInternetFile(hFile, pstrFileName, this,
    (dwAccess == GENERIC_READ));
    return pFile;=======================================================================
    我怎么看函数的实现呀?
      

  3.   

    CFtpConnection* m_Ftp_Conn;
              m_Ftp_Conn = pCis->GetFtpConnection( m_csServerAddr,
    pFtpI->Csa->GetAt(1), 
    pFtpI->Csa->GetAt(2),
    21,
    TRUE);//Connect to FTP Server
     
             CInternetFile*  ifp = m_Ftp_Conn->OpenFile(temp_ftp_name); char buffer[DL_BUFFER_SIZE];
    unsigned int amount_read = DL_BUFFER_SIZE;
    unsigned int total_read = 0;
    while (amount_read == DL_BUFFER_SIZE )
    {
    amount_read = ifp->Read(buffer, DL_BUFFER_SIZE);
    cfo.Write(buffer, amount_read);//Write this to our data file
    total_read += amount_read;
    } m_bDone = TRUE;
    cfo.Close();//Close the file
    m_Ftp_Conn->Close();
    delete m_Ftp_Conn;//Delete the ftp connection just to be safe
    return;上面的程序是不是有泄露啊?
    需要这样写么: ifp->Close();
                  delete ifp;
      

  4.   

    delete ifp;
    delete m_Ftp_Conn;这两句可以吗?没见你动态创建对象阿,函数内部创建的对象CInternetFile::Close
    virtual void Close( );
    Throw ( CInternetException );ResCloses a CInternetFile and frees any of its resources. If the file was opened for writing, there is an implicit call to Flush to assure that all buffered data is written to the host. You should call Close when you are finished using a file.调用这个就可以释放资源了