Thread: Problem with mfc?

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    5

    Question Problem with mfc?

    Hy,

    i hope someone could help me

    i have written an programm to controll an fpga card with an existing libary. The example programm was in c and i have to use c++ and the mfc for my project. I managed it to get rid of all error messages and the programm starts without any warnings but if i want to acess the dfpga board i get an Messagebox with the Error

    unhandled exception in kartentestprog.exe: 0xC0000005: Access Violation.

    Code:
    void CKartentestprogDlg::OnStart() 
    {
    	// TODO: Add your control notification handler code here
    	Sleep(1000);   
    	fpga[0] = 1;  // <-- here comes the error
    	fpga[1] = 0;
    }
    this is the inilization of the board wich works perfekt and all returns are ok.

    Code:
    int CKartentestprogDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
    {
    	if (CDialog::OnCreate(lpCreateStruct) == -1)
    		return -1;
    	
    	//connect the fpga and load the .hap file
    	microenable   *board;
    	fpga_design   *design;
    	volatile unsigned long *fpga;
    	int           rCode;
    	int           PlxClk  = 40;
    	int           FpgaClk = 100;
    	char          DesignName[128] = "kartentester.hap";
    
    	// -------------------------------------------------------------------
    	// initialization of hardware
    	// -------------------------------------------------------------------
    	board = initialize_microenable();
    	if (board==NULL) {
    		//intf ("hardware initialization failed (code %d) : %s\n",
    		//   Me_GetErrCode(NULL),Me_GetErrMsg(NULL));
    		MessageBox( "Hardwareinizialisation failed", "Error", MB_OK );
    		return -1;
    	}
    	//printf ("hardware initialization ok\n");
    	MessageBox( "Hardware inizialisation is ok", "No Error", MB_OK );
    
    
    	// -------------------------------------------------------------------
    	// load a design
    	// -------------------------------------------------------------------
    	design  = load_design(board,DesignName);   // available in standard path
    	if (design == NULL) {
    		//printf ("load design %s failed (code %d) : %s\n",
    		//	    DesignName,Me_GetErrCode(board),Me_GetErrMsg(board));
    		MessageBox( "Load of the Design failed", "Error", MB_OK );
    		return -1;
    	}
    	//printf ("load design ok\n");
    	MessageBox( "Load of the Design is ok", "No Error", MB_OK );
    
    
    	// -------------------------------------------------------------------
    	// set clocks
    	// -------------------------------------------------------------------
    	rCode  = set_plx_clk (board,design, PlxClk);
    	if (rCode) {
    		//intf ("setting plx clock to %d Mhz failed:  error code %d)\n",PlxClk,rCode);
    		MessageBox( "Clock Settings failed", "Error", MB_OK );
    		return -1;
    	}
    
    	rCode  = set_fpga_clk (board,design, FpgaClk);
    	if (rCode) {
    		//printf ("setting fpga clock to %d Mhz failed: error code %d)\n",FpgaClk,rCode);
    		MessageBox( "Clock Settings failed", "Error", MB_OK );
    		return -1;
    	}
    	//printf ("clock setting ok (plx: %d Mhz, Fpga: %d Mhz)\n",PlxClk,FpgaClk);
    	MessageBox( "Clock Settings are ok", "No Error", MB_OK );
    
    
    	// -------------------------------------------------------------------
    	// configure FPGA
    	// -------------------------------------------------------------------
    	rCode  = configure_fpga(board,design);
    	if (rCode) {
    		//printf ("configuration design %s failed: error code %d)\n",DesignName,rCode);
    		MessageBox( "configuration design failed", "Error", MB_OK );
    		return -1;
    	}
    	//printf ("configuration design %s ok\n",DesignName);
    	MessageBox( "configuration design is ok", "No Error", MB_OK );
    
    
    	// -------------------------------------------------------------------
    	// get the access pointer
    	// -------------------------------------------------------------------
    	fpga  = (volatile unsigned long *) GetAccessPointer (board);
    	if (fpga == NULL) {
    		//printf ("memory map failed: error code %d (%s))\n",Me_GetErrCode(board),Me_GetErrMsg(board));
    		MessageBox( "memory map failed", "Error", MB_OK );
    		return -1;
    	}
    	MessageBox( "Memory Map ok", "No Error", MB_OK );
    
    
    	
    	return 0;
    }
    SO i hope someone could tell my what this error is all about and where it might come from.

    Thanx for all answers

    Greets Joerg

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    5
    i thought it must have to do something with the declaration too, but i had tken the code most out of the example i hab for c.

    in nearly an beginner with c++

    Edit:

    Thank you i marked the redefinition of the variable as an comment and now it works real fine

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MFC problem
    By gadu in forum Windows Programming
    Replies: 5
    Last Post: 05-29-2009, 06:33 AM
  2. Creating and Empty MFC project in Visual Studio?
    By Swerve in forum Windows Programming
    Replies: 7
    Last Post: 11-01-2008, 04:43 PM
  3. Problem with MFC Wizard
    By okinrus in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2004, 04:09 PM
  4. ListView ImageList problem (MFC)
    By The Dog in forum Windows Programming
    Replies: 1
    Last Post: 09-12-2002, 12:08 PM
  5. MFC is Challenging :: C++
    By kuphryn in forum C++ Programming
    Replies: 8
    Last Post: 02-05-2002, 01:33 AM