Solved

regular MFC dll

Posted on 1999-01-12
2
597 Views
Last Modified: 2013-11-20
I have a regular dll (MFC) with just one function to export
***********************************
CZirtApp theApp;


extern "C" __declspec(dllexport) void F()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
AfxMessageBox("zirt");
//      MessageBox(NULL,"ZIRT","H",MB_OK);
}
***********************************

and a default SDI app with a menu item (zirt-> showzirt)

and command handler
void CZirtuserView::OnZirtShowzirt()
{
      // TODO: Add your command handler code here
      F();
}

and I declare

extern "C" __declspec(dllimport) void F();
in SDI and link to dll lib.

when I activate the showzirt menu item, I have an assertion
wincore.cpp line 884. this is a single threaded very simple
case. if I ignore the asserts, it doesnot fail, but I need
a very clean explanation of what is going on etc ??
0
Comment
Question by:hasmet
2 Comments
 
LVL 1

Author Comment

by:hasmet
ID: 1327533
Adjusted points to 150
0
 

Accepted Solution

by:
JoeDol earned 150 total points
ID: 1327534
You have two CWinApp objects (one in the MFC SDI app and another in your regular MFC DLL), you have two different sources of state informations for MFC.
The call made to AfxMessageBox() doesn't require you to give an owner window. MFC tries to find an owner window for the message box by itself.
When it does that it looks in its current state information.
As you made a AFX_MANAGE_STATE(AfxGetStaticModuleState()), the current state is the one of the DLL. When MFC found a possible window owner for the message box, it checks if this window is present in one of the map that allows MFC to connect a CWnd object to an HWND (Windows) object. As the window found was created in the state of the SDI app, the CWnd derived object is not present in the DLL state map, but well present in the SDI app state.
This is why you get the assertion message.
To verify this, just comment out your AFX_MANAGE_STATE, and you'll see that you don't get the assertion...
So the solution is either not to use the AfxMessageBox() or not using the AFX_MANAGE_STATE in this case, or passing a AFX_MODULE_STATE* to your function, so that you can use the AFX_MANAGE_STATE macro with the passed AFX_MODULE_STATE* object. It is then up to the caller to specify in which context you want your function to be called.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question