DLL Invocation section:{****************************************************************}{ }{Project:dlldebug}{Copyright (c) 2003, 2005}{Unit for Ucommonunit}{create:2003-01-05 by Lin Hongwei}{modify:2003-01-16 by Lin Hongwei}{ }{****************************************************************}UnitUcommonunit;InterfaceusesWindows, Sysutils, Forms;typeTrundll=procedure(DLLName, FormName, Formcaption:pchar; Aapp:tapplication; Scr:tscreen)stdcall;procedureRundllform (DLLName, FormName, formcaption:string; Aapp:tapplication; Scr:tscreen)stdcall;ImplementationprocedureRundllform (DLLName, FormName, formcaption:string; Aapp:tapplication; Scr:tscreen)stdcall;varRundll:trundll; Getdllhwnd:hwnd;beginGetdllhwnd:=LoadLibrary (PChar (DllName)); Try ifGetdllhwnd < + Then beginMessageBox (0,'did not find the attached DLL file, please confirm the program is complete! ', 'failed to load DLL', MB_OK); Exit; End; @RunDLL:= GetProcAddress (Getdllhwnd,'RunDLL'); if@RunDLL <>Nil Then TryRunDLL (PChar (Uppercase (Trim (DLLName)), PChar (Uppercase (Trim (FormName))), PChar (formcaption), AAPP,SCR); except RaiseException.Create('T'+ FormName +'does not exist! '); End; finallyFreeLibrary (Getdllhwnd); End;End;End. DLL:{****************************************************************}{ }{project:udlltest}{Copyright (c) 2003, 2005}{Unit for Udlltest}{create:2003-01-05 by Lin Hongwei}{modify:2003-01-16 by Lin Hongwei}{ }{****************************************************************}Libraryudlltest;usessysutils, Forms, Messages, variants, Windows, Classes, UFrmTestForm1inch 'Ufrmtestform1.pas' {Form1}, UFrmTestForm2inch 'Ufrmtestform2.pas' {Form2};vardllapp:tapplication; Dllscreen:tscreen;procedureRunDLL (DLLName, FormName, Formcaption:pchar; Aapp:tapplication; Scr:tscreen)stdcall;varTheclass:tpersistentclass; Aform:tform;beginApplication:=Aapp; Screen:=SCR; Registerclasses ([TForm1, TForm2]); Theclass:= GetClass ('T'+FormName); if(Theclass =Nil) ThenGetLastError; ifTheclass.inheritsfrom (tform) and(Theclass <> Tform) Then beginaform:= Tform (Theclass.Create).Create(Nil); Aform.caption:=formcaption; TryAform.showmodal; finally Freeandnil(aform); End; End;End;procedureDllunloadproc (Dwreason:dword);begin ifDwreason = Dll_process_detach Then beginApplication:= Dllapp;//RecoveryScreen: =Dllscreen; End;End;exportsRunDLL;beginDllapp:= Application;//Save the initial Application object in the DLLDllscreen: =Screen ; Dllproc:= @DLLUnloadProc;//ensure that the original application is restored when the DLL is unloadedDllunloadproc (dll_process_detach);End.
Http://www.cnblogs.com/kfarvid/archive/2010/07/16/1778930.html
The use of some DLLs in Delphi (to pass application and screen, it seems to forget to pass the hint control)