Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

class memory allocation error

Status
Not open for further replies.

cisotta

Programmer
Apr 23, 2004
9
0
0
IT
I'm struggling with this problem:
A class that I've built has 3 member variables, 13 variables that are associated with dialog controls and 13 member functions.
Starting from this point, if I try to add another member variable, of whatever type, with whatever name, it cause an error message when the program start: "unhandled exception in scena.exe 0xc000005: Access Violation". I can't explain this!
No problem if I add instead a member function, the application goes on working.

In InitInstance the class I've built is started this way:
CScenaDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();

Can anyone help me?
thanks,
francesco
 
Hi,
why you set m_pMainWnd = &dlg; ?
To start a dialog it's enough:
CScenaDlg dlg;
int nResponse = dlg.DoModal();

Have a look at the calling stack:
wich is the last C instruction you see?
Access Violation normally has to do with invalid pointers
Tell us more
 
Code:
  CScenaDlg dlg;
  m_pMainWnd = &dlg;
  int nResponse = dlg.DoModal();

This is standard MFC dialog app design (Masi:including setting the m_pMainWnd). ALL MFC dialog applications does this. You need to give us more info - particulary concerning the code you have written.
What does CScenaDlg's constructor and OnInitDialog do? Show code rather than explain with words.

/Per
[sub]
"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."[/sub]
 
I'm very sorry to have bothered you, the error was caused by a silly variable address storing.

The dialog app design had set these two lines aligned to left:

CScenaDlg dlg;
extern CScenaDlg *pScenaWnd;
pScenaWnd = &dlg;
m_pMainWnd = &dlg;

I have added the two indented lines in the middle, and the error was produced by the very last line. I changed it to:
m_pMainWnd = pScenaWnd
since it already contain the address of dlg, and all seems work right now!

Can't explain why....

Thanks to you
francesco
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top