Solved

regular MFC dll

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 173
bigDiff challenge 17 144
has22 challenge 11 111
Excel file not created as expected 7 112
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…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

710 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