From: Karim on
I have an MFC dll (which links dynamically to MFC) that is used by our
own MFC application. I recently moved some functionality that was
working fine from the application module to the DLL module.
Afterwards, I started seeing crashes inside of _AfxMsgFilterHook while
a message boxes, file dialogs and the ODBC selection dialog was being
displayed. It looks like the module state is invalid and it's
crashing during the AfxGetModuleState()->m_bDLL reference (my
assumption is that AfxGetModuleState is returing NULL).

Upon entry into the DLL, I'm using
AFX_MANAGE_STATE(AfxGetStaticModuleState()) to pop the DLL state onto
the stack. I should also say that other calls into the DLL that
eventually lead to a message box being displayed seem to work fine.

My current workaround is to set the module state ot the applications'
just before the call to the file dialog, odbc dialog and problem
message boxes. Then pop it off immediately afterwards. I don't like
that very much, though, and would like to find out why the state is
being lost.

Any thoughts?

From: Ajay Kalra on
What sort of MDD is it? Extension of Regular? If its a Regular MFC
DLL, you will need to use AFX_MANAGE_STATE and set the state
correctly. If its an extesion DLL, you should not use
AFX_MANAGE_STATE.

---
Ajay

> I have an MFC dll (which links dynamically to MFC) that is used by our
> own MFC application. I recently moved some functionality that was
> working fine from the application module to the DLL module.
> Afterwards, I started seeing crashes inside of _AfxMsgFilterHook while
> a message boxes, file dialogs and the ODBC selection dialog was being
> displayed. It looks like the module state is invalid and it's
> crashing during the AfxGetModuleState()->m_bDLL reference (my
> assumption is that AfxGetModuleState is returing NULL).
>
> Upon entry into the DLL, I'm using
> AFX_MANAGE_STATE(AfxGetStaticModuleState()) to pop the DLL state onto
> the stack. I should also say that other calls into the DLL that
> eventually lead to a message box being displayed seem to work fine.
>
> My current workaround is to set the module state ot the applications'
> just before the call to the file dialog, odbc dialog and problem
> message boxes. Then pop it off immediately afterwards. I don't like
> that very much, though, and would like to find out why the state is
> being lost.
>
> Any thoughts?


From: Karim on
It's a regular DLL that already calls AFX_MANAGE_STATE. That's the
problem. It seems to be losing state after invoking system dialogs
like the Open File dialog, message boxes and ODBC selection dialogs.

On Aug 27, 3:39 pm, Ajay Kalra <ajayka...(a)yahoo.com> wrote:
> What sort of MDD is it? Extension of Regular? If its a Regular MFC
> DLL, you will need to use AFX_MANAGE_STATE and set the state
> correctly. If its an extesion DLL, you should not use
> AFX_MANAGE_STATE.
>
> ---
> Ajay
>
> > I have an MFC dll (which links dynamically to MFC) that is used by our
> > own MFC application. I recently moved some functionality that was
> > working fine from the application module to the DLL module.
> > Afterwards, I started seeing crashes inside of _AfxMsgFilterHook while
> > a message boxes, file dialogs and the ODBC selection dialog was being
> > displayed. It looks like the module state is invalid and it's
> > crashing during the AfxGetModuleState()->m_bDLL reference (my
> > assumption is that AfxGetModuleState is returing NULL).
>
> > Upon entry into the DLL, I'm using
> > AFX_MANAGE_STATE(AfxGetStaticModuleState()) to pop the DLL state onto
> > the stack. I should also say that other calls into the DLL that
> > eventually lead to a message box being displayed seem to work fine.
>
> > My current workaround is to set the module state ot the applications'
> > just before the call to the file dialog, odbc dialog and problem
> > message boxes. Then pop it off immediately afterwards. I don't like
> > that very much, though, and would like to find out why the state is
> > being lost.
>
> > Any thoughts?