MFC Debug Assertion Failed (DLL Dialog Create Error)

채문석(jim) 41 Reputation points
2022-11-08T04:53:27.717+00:00

I am trying to CREATE a dialog as MODALESS in a DLL. When DEBUGING is attempted, DEBUG ASSERTION FAILED LINE24 is output. What should I do?

Code Example :
extern "C" __declspec(dllexport) int CreateDlg()
{
CTestDlg *pDlg = new CTestDlg;

pDlg->Create(IDD_DIALOG1); // This Code Error Message Print  
  
return 0;  

}

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,641 questions
{count} votes

Accepted answer
  1. RLWA32 43,641 Reputation points
    2022-11-08T10:11:46.9+00:00

    When you export a function from a regular MFC DLL the function must include AFX_MANAGE_STATE.

    For example,

       extern "C" __declspec(dllexport) int CreateDlg()  
       {  
       	AFX_MANAGE_STATE(AfxGetStaticModuleState());  
         
       	CModeless* pdlg = new CModeless;  
       	pdlg->Create(IDD_MODELESS);  
       	pdlg->ShowWindow(SW_SHOW);  
       	return 0;  
       }  
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. YujianYao-MSFT 4,281 Reputation points Microsoft Vendor
    2022-11-08T05:58:53.4+00:00

    Hi @채문석(jim) ,

    If you are trying to dynamically create a modeless dialog the following steps are required:

    Create a dialog box in the resource file, then right-click to select Add Class

    258078-image.png

    Add the header file of the dialog class in the .cpp file and then use the following code.

    258047-image.png

    CMyDlg *dlg = new CMyDlg;  
    dlg->Create(IDD_DIALOG1, NULL);  
    dlg->ShowWindow(SW_SHOW);  
    

    Best regards,

    Elya


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.