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

Thread: Append Data to CFile via FILE*

Threaded View

  1. #1
    Join Date
    Dec 2004
    Posts
    61

    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:
    [QUOTE]
    void SaveDocument(CString strFile)
    {
    CFile file;
    if( !file.Open(strFile, CFile::modeCreate | CFile::modeWrite | CFile::shareDenyNone))
    {
    CArchive ar(&file, CArchive::store);
    // save now.
    MyClass.Serialise(ar);

    ar.Flush();
    ar.Close();
    file.Close();
    }
    }

    void MyClass::Serialize(CArchive &ar)
    {
    if(ar.IsStoring())
    {
    ar << parameter1;
    ar << parameter2;
    ...

    ar.Flush();
    CFile *pFile = ar.GetFile();

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

    }

    }

    [\QUOTE]

    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?

    Thanks.
    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center