CFile error

This is a discussion on CFile error within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to open a CFile using this code: Code: ... CFile file; CFileException fileex; TCHAR cause[1024]; BOOL result=file.Open(dlg->GetPathName(), CFile::modeCreate ...

  1. #1
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596

    CFile error

    I'm trying to open a CFile using this code:

    Code:
    ...
        CFile file;
        CFileException fileex;
        TCHAR cause[1024];
    
        BOOL result=file.Open(dlg->GetPathName(),
                              CFile::modeCreate || CFile::modeNoTruncate ||  
                              CFile::modeWrite, &fileex);
    
        if (result==0)
        {
          fileex.GetErrorMessage(cause,1024);
    
          CString errorText;
          errorText.Format("Could not open file\n %s",cause);
    
          ::MessageBox(0,errorText,"ERROR",MB_ICONEXCLAMATION);
          return;
        }
    ...
    I get an internal compiler error number C1001. All optimizations are turned off for the debug version. This is happening in MSVC 6.

    Either way the file is not being opened because it says it cannot find it. However if you notice I use CFile::modeCreate which should create the file regardless if it exists or not.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    > CFile::modeCreate || CFile::modeNoTruncate
    I think you're using the wrong kind of 'or'
    Use the bitwise |, not the logical ||
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    OMG.

    I can't believe I didn't catch that.

    What a noob error.

  4. #4
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,262
    It's because of the double colons (:: ) everywhere.

    See? This is why I don't get into C++.

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Well it really threw the compiler off. It couldn't even recover enough to tell me what the error was except for internal compiler error C1001.

    It also threw the heap off, the stack off and several other things as well.
    I couldn't believe that all this could happen from 1 error like that. Even when it would compile w/o having CFile::modeNoTruncate, the CFile class still acted very weird as well as the CArchive class.

    When I would attempt to close the archive, it would assert horribly in release and debug versions, but it was inside of crtdebug.h which was ....um....not good.

    Sometimes even in the new MSVC 05 .NET it is still very hard to trace errors because the debugger constantly shows code that is not yours. I'm not sure if there is a way to prevent this since a programmer could cause an assertion in MSVCRT and in Kernel32.DLL due to improper use.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 03:09 AM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21