1, the writing method of the DLL program (MyFormdll.dll) build a DLL program first, add a new form for Form1 in it, this DLL program is: ------------------ -------------------------------------------------- -------
#include #include #include "unit1.h" #pragma hdrstop -------------------------- ------------------------------------------------- Important note about DLL memory management when your DLL uses the static version of the RunTime Library: If your DLL exports any functions that pass String objects (or structs / classes containing nested Strings) as parameter or function results, you will need to add the library MEMMGR .LIB to both the DLL project and any other projects that use the DLL. You will also need to use MEMMGR.LIB if any other projects which use the DLL will be performing new or delete operations on any non-TObject-derived classes which are exported from the DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling EXE's to use the BORLNDMM.DLL as their memory manager. In these cases, the file BORLNDMM.DLL should be deployed along with your DLL. to avoid Using borlndmm.dll, pass string information using "char *" or shortstri Ng parameters. if Your DLL Uses The Dynamic Version of The RTL, You Do Not Need To Explicitly Add Memmgr.lib As this Will Be Done Implicitly for you ---------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- ------- Extern "C" __declspec (dllexport) __stdcall void OpenMYFORM (HWND Handle); Extern "C" __DECLSPEC (DLLEXPORT) __stdcall void closemyform (void); useform ("Unit1.cpp", form1); int Formid = 0; #pragma argsusedint WinAPI DLLENTRYPOINT (Hinstance Hinst, unsigned long reason, void * lpreserved) {return 1;} ------------------------ -------------------------------------------------- -__ decspec (dllexport) __stdcall void openmyform (hwnd handle) {
IF (FormID == 0) {Application-> Handle = Handle; Application-> Createform (__ classid (tform1), & form1); FormID = 1;} form1-> show ();} __ decspec (dllexport) __stdcall void Closemyform (void ) {If (Formid == 1) {form1-> close (); formiD = 0;}} 2, dynamically call this DLL method, Unit1.cpp --------------- -------------------------------------------------- ------------
#include #pragma HDRSTOP
#include "unit1.h" ------------------------------------------- ------------------------------ # prgma package (smart_init) #pragma resource "* .dfm" tFormall * formall; Void __stdcall (hwnd); void __stdcall (* closemyform) (void); hinstance hmyformdll; --------------------------- ------------------------------------------------__ fastcall TFORMALL :: TFORMALL (Tcomponent * Owner: TFORM (OWNER) {hmyformdll = loadingLibrary ("myformdll.dll");} ------------------------- -------------------------------------------------- -