Solved

regular MFC dll

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

757 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

24 Experts available now in Live!

Get 1:1 Help Now