Append Data to CFile via FILE*
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 8 of 8

Thread: Append Data to CFile via FILE*

Threaded View

  1. #1
    Join Date
    Dec 2004

    Unhappy Append Data to CFile via FILE*

    Dear All,

    I having a problem here.
    I'm trying to append data to a CFile using FILE*
    But when execute the application, it always give error saying "No such file or directory".
    I can actually see the file created but it just keep giving error "No such file or directory".

    Is the file being lock or the file just created so it can not be find by fstream(FILE*)?
    or the file mode is wrong?

    Can somebody help me with this:
    Below is the code:
    void SaveDocument(CString strFile)
    CFile file;
    if( !file.Open(strFile, CFile::modeCreate | CFile::modeWrite | CFile::shareDenyNone))
    CArchive ar(&file, CArchive::store);
    // save now.


    void MyClass::Serialize(CArchive &ar)
    ar << parameter1;
    ar << parameter2;

    CFile *pFile = ar.GetFile();

    int fd = _open_osfhandle((long)(pFile->m_hFile), _O_APPEND); // fd is > 0
    pFILE = _wfdopen(fd, _T("a+"));
    CString str;
    str = strerror(errno);
    AfxMessageBox(str); // <=Here always give "No such file or directory"




    Attached is the printscreen of the FILE* pointer. the pointer is evaluated as bad pointer.
    Why the FILE* pointer not able point to the file being created?

    Attached Images Attached Images  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)