CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 39
  1. #1
    Join Date
    Jul 2006
    Posts
    219

    Access violation

    When I debug my program, it opens fine, but then it comes out with a debug message:

    Unhandled exeption in Environment.exe: 0xC0000005: Access violation.

    It stops at the [break] - [Disassembly]:
    (the yellow arrow is on the top)
    Code:
    CCCCCCCC   ???
    CCCCCCCD   ???
    CCCCCCCE   ???
    CCCCCCCF   ???
    CCCCCCD0   ???
    CCCCCCD1   ???
    CCCCCCD2   ???
    CCCCCCD3   ???
    CCCCCCD4   ???
    In the Call Stack:
    (the yellow arrow is on the top)
    Code:
    cccccccc()
    NTDLL! 77fbb272()
    NTDLL! 77facc28()
    NTDLL! 77f91bc6()
    NTDLL! 77facc28()
    NTDLL! 77f91bc6()
    NTDLL! 77facc28()
    NTDLL! 77f91bc6()
    NTDLL! 77facc28()
    NTDLL! 77f91bc6()
    NTDLL! 77facc28()
    What is the problem? Can anyone help me? Thanks.

  2. #2
    Join Date
    Jun 2005
    Location
    Tirunelveli-Tamil Nadu-India
    Posts
    354

    Thumbs up Re: Access violation

    hi

    can u post ur sample code...? ten only we can help u...
    If I Helped You, "Rate This Post"

    Thanks
    Guna

  3. #3
    Join Date
    Jul 2006
    Posts
    219

    Re: Access violation

    I debug it putting my cursor on one of the function, then I press F10 to go into it. It actually first stops at [run] - [Dissembly]:

    Code:
    77E3C1D5   call        77E3C043
    77E3C1DA   leave
    77E3C1DB   ret         4
    77E3C1DE   nop
    77E3C1DF   nop
    77E3C1E0   nop
    77E3C1E1   nop
    and in the Call Stack:
    Code:
    USER32! 77e3c1d5()
    NTDLL! 77f91baf()
    CTactileEnvironmentApp::InitInstance() line 127
    AfxWinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char * 0x001335e1, int 1) line 39 + 11 bytes
    WinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char * 0x001335e1, int 1) line 30
    WinMainCRTStartup() line 330 + 54 bytes
    KERNEL32! 7c5989a5()

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Access violation

    Please, post the code snippet around your "CTactileEnvironmentApp::InitInstance() line 127"

  5. #5
    Join Date
    Jul 2006
    Posts
    219

    Re: Access violation

    Quote Originally Posted by VictorN
    Please, post the code snippet around your "CTactileEnvironmentApp::InitInstance() line 127"
    I applied this code from somewhere and added to my code. I try to put as much related snippets as possible here.

    Code:
    BOOL CTactileEnvironmentApp::InitInstance()
    {
    	// InitCommonControls() is required on Windows XP if an application
    	// manifest specifies use of ComCtl32.dll version 6 or later to enable
    	// visual styles.  Otherwise, any window creation will fail.
    	InitCommonControls();
    
    	//LoadIcon(IDI_APPICON);
    	CWinApp::InitInstance();
    
    	// Initialize OLE libraries
    	if (!AfxOleInit())
    	{
    		AfxMessageBox("FAIL Initialize OLE libraries");
    		return FALSE;
    	}
    	AfxEnableControlContainer();
    
    	// Standard initialization
    	// If you are not using these features and wish to reduce the size
    	//  of your final executable, you should remove from the following
    	//  the specific initialization routines you do not need.
    
    #ifdef _AFXDLL
    	Enable3dControls();			// Call this when using MFC in a shared DLL
    #else
    	Enable3dControlsStatic();	// Call this when linking to MFC statically
    #endif
    
    	// Change the registry key under which our settings are stored.
    	// TODO: You should modify this string to be something appropriate
    	// such as the name of your company or organization.
    	SetRegistryKey(_T("TactileEnvironment"));
    
    	LoadStdProfileSettings(0);  // Load standard INI file options (including MRU)
    
    	// Register the application's document templates.  Document templates
    	//  serve as the connection between documents, frame windows and views.
    
    	CSingleDocTemplate* pDocTemplate;
    	pDocTemplate = new CSingleDocTemplate(
    		IDR_MAINFRAME,
    		RUNTIME_CLASS(CTactileEnvironmentDoc),
    		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
    		RUNTIME_CLASS(CTactileEnvironmentView));
    //		RUNTIME_CLASS(CTestView));
    	AddDocTemplate(pDocTemplate);
    
    	// Parse command line for standard shell commands, DDE, file open
    	CCommandLineInfo cmdInfo;
    	// If Not Parsed cmdInfo Will Not Get Values And Will Not Open cmdInfo.m_strFileName
    	// ParseCommandLine(cmdInfo);
    
    	// Dispatch commands specified on the command line
    	if (!ProcessShellCommand(cmdInfo))
    		return FALSE;
    
    	// The one and only window has been initialized, so show and update it.
    	m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
    	m_pMainWnd->UpdateWindow();
    
    	return TRUE;
    }
    
    //-----------------------------------------------------------------------------
    void CTactileEnvironmentView::OnDraw(CDC* pDC)
    //=============================================================================
    {
    	CTactileEnvironmentDoc* pDoc = GetDocument();
    	
    	CMainFrame* pMFrm = (CMainFrame*)AfxGetMainWnd();
    	
    	ASSERT_VALID(pDoc);
    
    	CSize viewWidth;
    	CRect rect;
    	int rectWidth;
    
    	GetWindowRect(&rect);
    	rectWidth = viewWidth.cx;
    	viewWidth.cx = rect.Width();
    
    	//CALL FROM COMMAND//
    	if ( first_time == true)
    	{
    		CWinApp* app=AfxGetApp( ); 
    		if (app->m_lpCmdLine[0] != _T('\0'))
    		{
    			char coman [500];
    			strcpy(coman,app->m_lpCmdLine);
    
    			char copySecArg[500], copySecArg2[500];
    			char *filePath, *fileExtension;
    
    			InArguments = strtok (coman, " ,");
    			while (InArguments != NULL) {
    				vecArguments.push_back(InArguments);
    				InArguments = strtok (NULL, " ,");
    			}
    			firstArg	= vecArguments[0];
    			secondArg	= vecArguments[1];
    			thirdArg	= vecArguments[2];
    
    			int intThirdArg;
    			intThirdArg = atoi( thirdArg );
    			numTop = intThirdArg;
    
    			strcpy(copySecArg, secondArg);
    			strcpy(copySecArg2, copySecArg);
    			
    			filePath = strtok(copySecArg, ".");
    
    			fileExtension = strtok (NULL, " ,\t\n");
    
    			if (!strcmp(firstArg,"graph") )
    			{			
    				if (!strcmp (fileExtension, "svg"))
    				{
    					eGraph_data gr_axis;
    					gx=gr_axis;
    
    					extern void graph_import_svg(char *filename, eGraph_data& gr_axis);
    					graph_import_svg(copySecArg2,gx);
    					
    					double range[2];
    					
    					range[0]= 10000000000;
    					range[1]= -10000000000;
    					
    					double *table= gx.r_table();
    					int num_row=gx.r_num_row();
    					for (int i=0;i< num_row;i++)
    					{
    						for(int j=0;j<gx.r_num_col();j++)
    						{
    							if ( range[0] > table[i*NMAXDATA+j])
    								range[0]=table[i*NMAXDATA+j];
    							if ( range[1] < table[i*NMAXDATA+j])
    								range[1]=table[i*NMAXDATA+j];
    						}
    					}
    					
    					if ( range[0]== 10000000000)
    						range[0]=0.;
    					if (range[1]== -10000000000)
    						range[1]=0.;
    					
    					if ( range[1] <=range[0])
    						range[1]= range[0]+ 1.;
    					gx.set_range(range[0],range[1]);
    
    					FileSelected = TRUE;
    
    					OnPaint();
    				}
    			} else if (!strcmp(firstArg,"bitmap") ) {			
    				if (!strcmp (fileExtension, "gif"))
    				{
    					pDoc->m_FilePathName= copySecArg2;
    				}
    			}
    		}
    	}
           SetScrollSizes(MM_TEXT, m_ScrollSizeTotal);
    }
    The second function is where I think it might be problem. It basically read the arguments sent to it. I execute without arguments, it seems fine. When I put in arguments to execute it, then there is problem.

    Thanks.

  6. #6
    Join Date
    Nov 2005
    Location
    India, Kerala, Trivandrum
    Posts
    37

    Re: Access violation

    I think it's got something to do with not initializing variables properly. Can you step through your code and find out. Set a break point inside OnDraw and find out what's the trouble.

  7. #7
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: Access violation

    Have you tried debugging it line by line? After what line does this exception occur?
    Regards,
    Ramkrishna Pawar

  8. #8
    Join Date
    Jun 2005
    Location
    Tirunelveli-Tamil Nadu-India
    Posts
    354

    Thumbs up Re: Access violation

    hi

    CWinApp::InitInstance(); comment this line debug ur program... its may be reason...
    If I Helped You, "Rate This Post"

    Thanks
    Guna

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Access violation

    1. CWinApp::InitInstance() method does nothing, it just returns TRUE; so noone needs to call it.
    2. Where is the line 127?

  10. #10
    Join Date
    Jul 2006
    Posts
    219

    Re: Access violation

    Quote Originally Posted by VictorN
    1. CWinApp::InitInstance() method does nothing, it just returns TRUE; so noone needs to call it.
    I already delete the CWinApp::InitInstance, but it still the same problem.

    2. Where is the line 127?[/QUOTE]
    Line 127 is: return TRUE;

  11. #11
    Join Date
    Jul 2006
    Posts
    219

    Re: Access violation

    Quote Originally Posted by Krishnaa
    Have you tried debugging it line by line? After what line does this exception occur?
    I did this. It also stops at [run]-[Disassembly]

    Code:
    77E3C047   int         2Bh
    77E3C049   ret         4
    77E3C04C   nop
    77E3C04D   nop
    77E3C04E   nop
    77E3C04F   nop
    77E3C050   nop
    77E3C051   mov         eax,eax
    77E3C053   push        ebp
    In the Call Stack:
    Code:
    USER32! 77e3c047()
    NTDLL! 77f91baf()
    CTactileEnvironmentApp::InitInstance() line 127
    AfxWinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char * 0x001335e1, int 1) line 39 + 11 bytes
    WinMain(HINSTANCE__ * 0x00400000, HINSTANCE__ * 0x00000000, char * 0x001335e1, int 1) line 30
    WinMainCRTStartup() line 330 + 54 bytes
    KERNEL32! 7c5989a5()

  12. #12
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Access violation

    Quote Originally Posted by samallis
    Code:
    // The one and only window has been initialized, so show and update it.
    	m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
    	m_pMainWnd->UpdateWindow();
    You are using this code, but where did you allocate/initialize the m_pMainWnd pointer? Where is the m_pMainWnd->LoadFrame(...) call?

  13. #13
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: Access violation

    Generally these problems are seen with reference to stack corruption (return address of function modified because of out of bounds writing), can happen with strings, strangly I dont see much code which can do this, can you post your project(entire, after deleting debug/release folders and intermidiate files) here so that someone can have a detailed look?
    Regards,
    Ramkrishna Pawar

  14. #14
    Join Date
    Jul 2006
    Posts
    219

    Re: Access violation

    Quote Originally Posted by VictorN
    You are using this code, but where did you allocate/initialize the m_pMainWnd pointer? Where is the m_pMainWnd->LoadFrame(...) call?
    I don't have any m_pMainWnd->LoadFrame();. I have this project from somewhere else. I thought it is fine and I just add my part in it.

    I have this:
    Code:
    m_pMainWnd->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, 0, 0);
    m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
    m_pMainWnd->UpdateWindow();
    It says that
    Error C2039: 'LoadFrame' : is not a member of 'CWnd'...

  15. #15
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Access violation

    Quote Originally Posted by samallis
    ...
    It says that
    Error C2039: 'LoadFrame' : is not a member of 'CWnd'...
    Yes, of course!
    it should look like (it is - from standard MDI InitInstance implementation):
    Code:
    	// create main MDI Frame window
    	CMainFrame* pMainFrame = new CMainFrame;
    	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
    		return m_bInitInstOK;
    
    	m_pMainWnd = pMainFrame;

Page 1 of 3 123 LastLast

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