FORM problem in DLL
When making large projects, it is a general practice through a master program (EXE) with N DLL mode, which is the advantage of this:
1. Easy to pass the modularization of the project, you can package logically similar modules;
2, easy to develop at the same time, because each DLL function is relatively independent, can be developed in parallel;
3, easy to post-release maintenance and upgrade, you can modify and publish a single single DLL during maintenance, which will not affect other modules.
Of course, there are other benefits, I think of this, everyone added (^ _ ^ lazy!)
Since there is so much benefit, I decided to use this mode when I develop a project, and my development tool is C Builder.
As a result, I met a number of problems just at the beginning (I found a while in the Internet, and the results found that the people said that they were all, but they also gave me a lot of inspiration).
I started to set up a MDIFORM in EXE, and then I want to place multiple MdichildForm in the DLL. The probably code is as follows:
Host:
FormStyle is set to FSMDIFORM
MyShowForm (Application-> Handle, ASCAPTION)
DLL:
FormStyle is set to fsmdichild
THANDE * DLLHANDLE;
MyShowForm (Thandle * Handle, Ansistring Ascaption)
{
DllHandle = Application-> Handle; // Save DLL Handle
Application-> Handle = Handle; // Use EXE's HANDLE
IF (ascaption == "form1")
{
Form1 = new TFORM1 (Application-> Handle);
}
Else
...
}
The results have found that this usage problem, if DLL gets focus, the Tab keys and Enter keys do not work, there is a problem when exiting.
I think this is because EXE and DLL are not in the same address space, and EXE and DLL maintain their memory space separately.
Plus I want to put the form in the DLL in a control in the form of the exe, so I use the following way:
Host:
FormStyle is set to FSNORMAL (set to FSMDIFORM)
Create a call for MyShowForm (Control, Ascaption);
Turn off MYDELETEFORM (ASCAPTION);
DLL:
FormStyle must be set to FSNORMAL
MyShowForm (TwinControl * wcparent, ANSISTIRNG ASCAPTION)
{
IF (ascaption == "form1")
{
IF (Form1 == Null)
{
Form1 = new TFORM1 (NULL);
FORM1-> PARENT = WCPARENT;
}
FORM1-> show ();
}
Else
...
}
Mydeleteform (ANSISTRING ASCAPTION)
{
IF (ascaption == "form1")
{
DELETE FORM1;
Form1 = NULL;
}
}