Thread: CFile in MFC

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    465

    CFile in MFC

    i am having problems writing to a file. i am getting an access violation writing to the file. ive dug through the documentation for about an hour and i still cant figure out what im doing wrong.

    here is my save code

    Code:
    void CChildView::SaveMap( CString path )
    {
    	CFile file;
    
    	const int SizeOfBuffer = mapSz.x * mapSz.y;
    	int * buffer = new int [ SizeOfBuffer ];
    
    	int sizeBuffer[2];
    
    	try 
    	{
    		file.Open( path, CFile::modeCreate );
    
    		sizeBuffer[0] = mapSz.x;
    		sizeBuffer[1] = mapSz.y;
    
    		for ( int i = 0; i < mapSz.y; ++i )
    		{
    			for ( int j = 0; j < mapSz.x; ++j )
    			{
    				buffer[i * mapSz.x + j] = map[i][j];
    			}
    		}
    
    		file.Write( sizeBuffer, 2 * sizeof(int));
    		file.Write( buffer, SizeOfBuffer * sizeof(int));
    
    	}
    
    	catch (void)
    	{
    		MessageBox( "An error occured while writing to the file" );
    	}
    
    	delete [] buffer;
    
    	file.Close();
    
    	mapHasBeenEdited = FALSE;
    	
    }
    Last edited by ...; 10-21-2003 at 09:22 PM.
    I came up with a cool phrase to put down here, but i forgot it...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WIndows programming?
    By hostensteffa in forum Windows Programming
    Replies: 7
    Last Post: 06-07-2002, 08:52 PM
  2. Release MFC Programs & Dynamic MFC DLL :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-18-2002, 06:42 PM
  3. Understanding The Future of MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 04-15-2002, 09:08 PM
  4. Beginning MFC (Prosise) Part III - Now What? :: C++
    By kuphryn in forum C++ Programming
    Replies: 5
    Last Post: 03-03-2002, 06:58 PM
  5. MFC is Challenging :: C++
    By kuphryn in forum C++ Programming
    Replies: 8
    Last Post: 02-05-2002, 01:33 AM