Solved

regular MFC dll

Posted on 1999-01-12
2
596 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get filename and folder into excel 7 68
Expand macro to ask for filename column 8 37
Tab names are off by one 5 53
notReplace  challenge 53 116
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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now