Assertion Error :(

This is a discussion on Assertion Error :( within the Windows Programming forums, part of the Platform Specific Boards category; I am getting this error only when compiling in debug mode. It saves the files alright but I get this ...

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Assertion Error :(

    I am getting this error only when compiling in debug mode. It saves the files alright but I get this after I close the window.

    Code:
    int SaveClientInfo(HWND DialogHandle)
    
    {
    
    
    	HANDLE File;
    	Client Cliente;
    	HWND NameEditBoxHwnd;
    	HWND NameEditBox;
    	DWORD dwWritten;
    	HWND  AddressBoxHandle;
    	char * NameOfFile;
    	char *FileToSave;
    	char *NameOfClient;
    	char *ClientAddress;
    	int iCount;
    
    	ZeroMemory(&Cliente,sizeof(Cliente));
    
    	
    
    	NameEditBoxHwnd=GetDlgItem(DialogHandle, IDC_NOMBRE);
    	iCount=GetWindowTextLength(NameEditBoxHwnd);
    	
    	//we incremente iCount to accomodate for the NULL character
    	NameOfFile=new char [iCount];
    	GetWindowText(NameEditBoxHwnd,NameOfFile,iCount+1);
    	FileToSave= new char [sizeof(NameOfFile)];
    
    	
        OpenFileName.hwndOwner         = NULL;
        OpenFileName.lpstrFile          = NameOfFile;
       OpenFileName.lpstrFileTitle	   =FileToSave;
        OpenFileName.Flags              = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT ;
    	
    	GetSaveFileName (&OpenFileName);
    
    		
    	NameEditBox=GetDlgItem(DialogHandle, IDC_NOMBRE);
    	iCount=GetWindowTextLength(NameEditBox);
    	NameOfClient=new char [iCount];
    	GetWindowText(NameEditBox,NameOfClient,iCount+1);
    	Cliente.SetName(NameOfClient);
    
    
    
    
    	AddressBoxHandle=GetDlgItem(DialogHandle,IDC_ADDR);
    	iCount=GetWindowTextLength(AddressBoxHandle);
    	ClientAddress=new char [iCount];
    	GetWindowText(AddressBoxHandle,ClientAddress,iCount+1);
    	Cliente.SetAddress(ClientAddress);
    
    
    
    
    	File=CreateFile(OpenFileName.lpstrFileTitle, GENERIC_WRITE, 0, NULL,
            CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    
    		                    
    
        WriteFile(File, (char*)&Cliente, sizeof(Cliente), &dwWritten, NULL);
                          
    
    
    	/* I am having some serious problems with this stuff
    	upon closing the window the program crashes....
    	how would I free the pointer memory? 
    
    	delete Pointer;
    	Pointer=NULL;
    
    	Should  I do this here? 
    	Remember that this is called more than once thruout the program
    	I think that it's because I am not freeing memory properly
    
       */
    
    	GlobalFree(NameOfFile);
    	GlobalFree(FileToSave);
    	GlobalFree(NameOfClient);
    	GlobalFree(ClientAddress);
    
    
    	CloseHandle(File);
    
    
    
    
    
    	return Success;
    
    	
    	
    }
    Attached Images Attached Images  
    Last edited by incognito; 12-19-2003 at 07:32 AM.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    What I've found wrong so far:

    Code:
    NameOfFile=new char[iCount];
    GetWindowText(NameEditBoxHwnd, NameOfFile, iCount + 1);
    should be:
    Code:
    NameOfFile=new char[iCount + 1];
    GetWindowText(NameEditBoxHwnd, NameOfFile, iCount + 1);
    You need one more char for the null character.


    Code:
    FileToSave= new char[sizeof(NameOfFile)];
    NameOfFile is char* so sizeof(NameOfFile) == 4, use iCount + 1 instead.

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. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 03:35 PM
  4. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  5. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM

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