1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

assertion error with C++ Dll using CDialog

Discussion in 'MFC' started by worker-bee, Sep 3, 2010.

  1. worker-bee

    worker-bee New Member

    Sep 3, 2010
    Likes Received:
    Trophy Points:
    Can anyone help me with this?

    I’m getting an assert error when I exit out of my main app (C#) after calling my dll (C++). The error is Debug Assertion Failed! Program:… File: f:\...appcore.cpp Line: 862. I’ve researched this problem and it appears I needed AFX_MANAGE_STATE(AfxGetStaticModuleState()); which is the first line in the dll function but the problem still exists. I also am using debug versions on my main app and dll. This assertion error only occurs when I’m calling a function that generates a dialog box (CDialog). When I call other functions that do some calculations there are no errors. I’m using Visual Studio V2005. Here are the code excerpts. Thanks in advance.

    /// code from assertion appcore.cpp
    	// Cleanup DAO if necessary
    	if (m_lpfnDaoTerm != NULL)
    		// If a DLL, YOU must call AfxDaoTerm prior to ExitInstance
    		ASSERT(!afxContextIsDLL);//here is where things stop
    /// code from DLL (uses MFC as shared DLL)
    extern "C" int EXPORT Get_The_Material(char  *MaterialName);
    //Microsoft suggests this macro to be called first, see above
    if (IDOK == FM.DoModal()) {
    	if (FM.iItem != -1) { // user selected a material
    ……… rest of code
    Return 1;
    /// code from C# calling application
    namespace WindowsApplication1
        public partial class Form1 : Form
            public Form1()
            unsafe private static extern int Get_The_Material(byte[] TradeName);
    unsafe private void btnMyDLL_Click(object sender, EventArgs e)
                  byte[] TradeName;
                    TradeName = new byte[50];
    …. Rest of code

Share This Page