Home > Software engineering >  DLL dialog box shown in the main program
DLL dialog box shown in the main program

Time:10-06

Due to the need of project, want to be in a DLL (DLL project requirement rules, are not allowed to use extension DLL) encapsulated in the dialog box, the main program is loaded, in child window way, according to the results found that the main program in the calling CDialog: : Create, change this pointer, for later use this pointer, abnormal program

The main program code below

BOOL CtestDlg: : OnInitDialog ()
{
CDialog: : OnInitDialog ();

PFunGetUI typedef int (*) (void * & amp; P_dlg, unsigned int& I_dlg_id);

HINSTANCE hExeIns=AfxGetInstanceHandle ();
HINSTANCE HINSTANCE=LoadLibrary (L "XXX. DLL");

PFunGetUI getUI=(pFunGetUI) GetProcAddress call (hInstance, "getUI");

AfxSetResourceHandle (hInstance);

Unsigned int dlg_id=0;
CDialog * pDlg=0;
GetUI ((void * & amp;) PDlg dlg_id);

If (pDlg - & gt; Create (dlg_id)==FALSE) //this step a success, but the main program this pointer has changed, as if out of memory the
return FALSE;

AfxSetResourceHandle (hExeIns);
//behind if you use this pointer will be abnormal

}


DLL export functions to achieve the following

CMyUI * myUI=0;//global variables, based on a CDialog
DLL_EXPORT_API int GetUI (void * & amp; P_dlg, unsigned int & amp; I_dlg_id)
{
AFX_MANAGE_STATE (AfxGetStaticModuleState ());
MyUI=new CMyUI;

//pointer dialog:
P_dlg=myUI;
//dialog template ID:
I_dlg_id=IDD_MYUI;

return 0;
}

CodePudding user response:

This is not a special case, I try to write a lot of MFC DLL test, will be in this way, if the call will no longer do other operations, the Create page can display properly, but as long as a use this pointer, or access to any member variable of the main program, will be abnormal

CodePudding user response:

Read through the DLL in the MSDN development related chapters,

CodePudding user response:

Zhao four teachers, the reply is too general, suspected I yo

CodePudding user response:

Environment, the up

CodePudding user response:

You in OnInitDialog () using AfxSetResourceHandle (hInstance); Actually, this function is invalid, because the dialog resource is already loaded came in, so that is can't change the resources, is a must to replace in haven't create window is loaded, you can in the InitInstance (), if you want to display the dialog box in a DLL, can do processing in a DLL

CodePudding user response:

Model has been limited, can only be created in the main dialog window, is such a demand, the demand for the main program can load the DLL, but can't see the source doesn't know loading logic, since the program can show, there was a way to realize

CodePudding user response:

In the main program InitInstance try to load and still have the same problem

CodePudding user response:

DLL in the dialog box operation should be AFX_MANAGE_STATE (AfxGetStaticModuleState ()); Within the scope of the

Therefore recommended for the Create also on DLL

CodePudding user response:

That's strange, the customer give program is how to implement, okay, I can only try to Create within the DLL

CodePudding user response:

refer to the eighth floor zgl7903 response:
DLL in the dialog box operation should be AFX_MANAGE_STATE (AfxGetStaticModuleState ()); Within the scope of the

Therefore recommended for the Create also on DLL


The original poster should be in accordance with the above this way to do it, and within the DLL is to provide a global best Show function is responsible for the dialog box is displayed, do not go after the Load the DLL, according to the structure and then should go to call DLL in your Show to display the dialog box packaging

CodePudding user response:

references to the tenth floor pcradio response:
Quote: refer to the eighth floor zgl7903 response:

DLL in the dialog box operation should be AFX_MANAGE_STATE (AfxGetStaticModuleState ()); Within the scope of the

Therefore recommended for the Create also on DLL


The original poster should be in accordance with the above this way to do it, and within the DLL is to provide a global best Show function is responsible for the dialog box is displayed, do not go after the Load the DLL, according to the structure and then should go to call DLL you encapsulate Show to display the dialog box in the

Agree to
Or you could rewrite the Create, but in a DLL

CodePudding user response:

reference koower2010 reply: 3/f
4 teacher zhao, this reply is too general, suspected I yo

There are more general than this:
Baidu search relevant keywords,
  • Related