CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 1999
    Posts
    118

    Help! I can't create a file!



    I try to create a file with this code :

    DWORD dwWritten;

    HANDLE myNewFile;

    try

    {

    myNewFile = CreateFile(newFileName,

    GENERIC_WRITE,

    FILE_SHARE_WRITE,

    NULL,

    CREATE_NEW,

    FILE_ATTRIBUTE_NORMAL,

    NULL);

    WriteFile(myNewFile,

    &pDouble,

    myFile.GetLength(),

    &dwWritten,

    NULL);

    CloseHandle(myNewFile);

    }

    catch (CDaoException* e)

    {

    AfxMessageBox(e->m_pErrorInfo->m_strDescription);

    e->Delete();

    }

    But no file is created!!!

    The compiler says there is no error and no warning.

    Could anyone help me find what's wrong in the code?


    Thanks a lot.



  2. #2
    Join Date
    May 1999
    Location
    Antwerp, Belgium
    Posts
    136

    Re: Help! I can't create a file!



    If you just want simple read/write : it's easier to use streams.

  3. #3
    Join Date
    Jan 2002
    Location
    Boston, MA
    Posts
    4

    Re: Help! I can't create a file!

    I can't help with your code, but here is an easy way to write files.

    add a memeber variable e.g. CStdioFile m_fLog;

    Open or create the file if it doesn't exist:

    //open or create logfile for writing
    m_fLog.Open("temp.txt",CFile::modeCreate
    |CFile::modeNoTruncate
    |CFile::modeWrite);
    m_fLog.SeekToEnd();//append mode




    write to the file (you can write CStrings instead of the constant text below)

    m_fLog.WriteString("Hello file\n");




    close the file

    m_fLog.Close();




    You can read the file with m_fLog.ReadString. I hope this helps.


  4. #4
    Join Date
    May 2002
    Posts
    1

    Re: Help! I can't create a file!

    Hej my names is Julian.
    And I am also a beginner in visual basic and i think that you should not have so much lines.
    Try to make fewer lines.


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured