library CalendarLib;<br><br>uses<br> ShareMem,<br> SysUtils,<br> Classes,<br> DLLFrm in 'DLLFrm.pas' {DLLForm},<br> LoginFrm in 'LoginFrm.pas' {LoginForm};<br><br>exports<br> ShowCalendar,<br> Password;<br><br>begin<br>end.<br><br>unit LoginFrm;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls;<br><br>type<br> TLoginForm = class(TForm)<br> Button1: TButton;<br> Edit1: TEdit;<br> procedure Button1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>{ Declare the export function }<br>function Password(AHandle: THandle; ACaption: String; Password:string): Pchar; StdCall;<br><br>implementation<br><br>{$R *.dfm}<br><br>function Password(AHandle: THandle; ACaption: String; Password:string): Pchar;<br>var<br> LoginForm: TLoginForm;<br>begin<br> Application.Handle := AHandle;<br> LoginForm := TLoginForm.Create(Application);<br> try<br> LoginForm.Caption := ACaption;<br> LoginForm.ShowModal;<br> Result := Pchar(LoginForm.Edit1.text); <br> finally<br> LoginForm.Free;<br> end;<br>end;<br><br>procedure TLoginForm.Button1Click(Sender: TObject);<br>begin<br> Close;<br>end;<br><br>end.<br><br>unit DLLFrm;<br><br>interface<br><br>uses<br> SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,<br> Forms, Dialogs, Grids, Calendar;<br><br>type<br><br> TDLLForm = class(TForm)<br> calDllCalendar: TCalendar;<br> procedure calDllCalendarDblClick(Sender: TObject);<br> end;<br><br>{ Declare the export function }<br>function ShowCalendar(AHandle: THandle; ACaption: String): TDateTime; StdCall;<br><br>implementation<br>{$R *.DFM}<br><br>function ShowCalendar(AHandle: THandle; ACaption: String): TDateTime;<br>var<br> DLLForm: TDllForm;<br>begin<br> Application.Handle := AHandle;<br> DLLForm := TDLLForm.Create(Application); <br> try<br> DLLForm.Caption := ACaption;<br> DLLForm.ShowModal;<br> Result := DLLForm.calDLLCalendar.CalendarDate;<br> finally<br> DLLForm.Free;<br> end;<br>end;<br><br>procedure TDLLForm.calDllCalendarDblClick(Sender: TObject);<br>begin<br> Close;<br>end;<br><br>end.<br><br>unit MainFfm;<br><br>interface<br><br>uses<br> SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,<br> Forms, Dialogs, StdCtrls;<br><br>type<br> TShowCalendar = function (AHandle: THandle; ACaption: String): TDateTime; StdCall;<br> TPassword = function (AHandle: THandle; ACaption: String; Password:string): Pchar; StdCall;<br><br> EDLLLoadError = class(Exception);<br><br> TMainForm = class(TForm)<br> lblDate: TLabel;<br> btnGetCalendar: TButton;<br> Button1: TButton;<br> procedure btnGetCalendarClick(Sender: TObject);<br> procedure Button1Click(Sender: TObject);<br> end;<br><br>var<br> MainForm: TMainForm;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TMainForm.btnGetCalendarClick(Sender: TObject);<br>var<br> LibHandle : THandle;<br> ShowCalendar: TShowCalendar;<br>begin<br><br> LibHandle := LoadLibrary('CALENDARLIB.DLL');<br> try<br> if LibHandle = 0 then<br> raise EDLLLoadError.Create('Unable to Load DLL');<br> @ShowCalendar := GetProcAddress(LibHandle, 'ShowCalendar');<br> if not (@ShowCalendar = nil) then<br> lblDate.Caption := DateToStr(ShowCalendar(Application.Handle, Caption))<br> else<br> RaiseLastWin32Error;<br> finally<br> begin<br> FreeLibrary(LibHandle);<br> end;<br> end;<br>end;<br><br>procedure TMainForm.Button1Click(Sender: TObject);<br>var<br> LibHandle : THandle;<br> Password : TPassword;<br>begin<br> LibHandle := LoadLibrary('CALENDARLIB.DLL');<br> try<br> if LibHandle = 0 then<br> raise EDLLLoadError.Create('不能装载Dll文件');<br> @Password := GetProcAddress(LibHandle, 'Password');<br> if not (@Password = nil) then<br> showmessage(Password(Application.Handle, Caption,''))<br> else<br> RaiseLastWin32Error;<br> finally<br> FreeLibrary(LibHandle);<br> end;<br>end;<br><br>end.