Solved

regular MFC dll

Posted on 1999-01-12
2
615 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

630 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