error throws while closing the main window

Hi All,

In my SDI application while closing the main windows it throws error. while debuging control stucks at

// detect the case that this is the last frame on the document and
// shut down with OnCloseDocument instead. winfrm.cpp

if (pDocument != NULL && pDocument->m_bAutoDelete)

First-chance exception in Project1.exe (MFC42D.DLL): 0xC0000005: Access Violation.

please help me to solve this
[447 byte] By [sudeephooli] at [2007-11-20 11:36:31]
# 1 Re: error throws while closing the main window
What is the value of pDocument? Is it NULL?
Is your "SDI application" a standard MFC SDI App created by AppWizard or you created it by hand?
VictorN at 2007-11-10 22:24:57 >
# 2 Re: error throws while closing the main window
pDocument value is NOT NULL,
it shows 0x013b5510 {CDocument }

and if I expand the pDocument it shows

m_bModified -572662307
m_bAutoDelete -572662307
m_bEmbedded -572662307

MFC SDI App is not created by AppWizard, it's created by hand.

Thanks
sudeephooli at 2007-11-10 22:25:57 >
# 3 Re: error throws while closing the main window
and if I expand the pDocument it shows

m_bModified -572662307
m_bAutoDelete -572662307
m_bEmbedded -572662307Sounds like not initialized or already freed memory. :confused:

MFC SDI App is not created by AppWizard, it's created by hand.
Not a good idea, IMHO. In this case it is hard to find out the reason of the problem without seeing the code. :sick:
VictorN at 2007-11-10 22:27:00 >
# 4 Re: error throws while closing the main window
Actuall I am converting the existing SDI App to a regular DLL.

So I copied all the code from the existing SDI APP to this new DLL project, everything works fine except that closing the main window.

I am using the Regular dll becasue the client program is VB.

Is there any way to convert SDI app to regular DLL, which is called from VB application.
sudeephooli at 2007-11-10 22:28:00 >
# 5 Re: error throws while closing the main window
Don't you forget to (from MSDN article "Regular DLLs Dynamically Linked to MFC")use the AFX_MANAGE_STATE macro at the beginning of every function exported from the DLL.
VictorN at 2007-11-10 22:29:09 >
# 6 Re: error throws while closing the main window
I am exporting whole class like this

class _declspec(dllexport) CStgcalApp : public CWinApp

is it necessary to put AFX_MANAGE_STATE all functions once you exported whole class.
sudeephooli at 2007-11-10 22:30:08 >
# 7 Re: error throws while closing the main window
If those functions are going to be used from outside program directly, it is necessory to switch the MFC State to current DLL, else the framework will look for the resources in callers MFC state.

It's safe to use them in all of those exported functions.
Krishnaa at 2007-11-10 22:31:11 >
# 8 Re: error throws while closing the main window
Looks like the document's already deleted but you still have a pointer. CDocuments will automatically delete themselves when they close unless you set m_bAutoDelete to FALSE. Perhaps that's your problem.
GCDEF at 2007-11-10 22:32:07 >