J
jesse.carrington
I have an application where I need to allow user to create multiple
Excel worksheets everytime a button is pressed. Basically, every time
they press a button (generate) a new instance of Excel starts and I
populate the cells and then do a SetUserControl. This all works great
until I go to exit the excel apps. The last app that I created exits
fine but all of the others give the error:
"The instruction at "0x650b5850" referenced memory at "0x650b5850".
The memory could not be "read"."
It seems that the "delete" of the _Application pointer is causing the
problem (I don't do delete the last instance until the destructor). I
have my _Application pointer as a member variable but if I make it
local I have the same problem. If I close my application before I
close the Excel files then I do not have a problem either.
Here is a snippet of my code:
void CMyDlg::Ongenerate()
{
if(m_p_app != NULL)
{
delete m_p_write_app;
}
m_p_write_app = new _Application;
if(!m_p_write_app->CreateDispatch("Excel.Application"))
{
AfxMessageBox("Couldn't start Excel.");
delete m_p_write_app;
m_p_write_app = NULL;
}
Excel worksheets everytime a button is pressed. Basically, every time
they press a button (generate) a new instance of Excel starts and I
populate the cells and then do a SetUserControl. This all works great
until I go to exit the excel apps. The last app that I created exits
fine but all of the others give the error:
"The instruction at "0x650b5850" referenced memory at "0x650b5850".
The memory could not be "read"."
It seems that the "delete" of the _Application pointer is causing the
problem (I don't do delete the last instance until the destructor). I
have my _Application pointer as a member variable but if I make it
local I have the same problem. If I close my application before I
close the Excel files then I do not have a problem either.
Here is a snippet of my code:
void CMyDlg::Ongenerate()
{
if(m_p_app != NULL)
{
delete m_p_write_app;
}
m_p_write_app = new _Application;
if(!m_p_write_app->CreateDispatch("Excel.Application"))
{
AfxMessageBox("Couldn't start Excel.");
delete m_p_write_app;
m_p_write_app = NULL;
}