这是一段<br>动态调用的代码,你看看对你有没有帮助吧<br>interface<br><br>uses<br> SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,<br> Forms, Dialogs, StdCtrls;<br><br>type<br> { First, define a procedural data type, this should reflect the<br> procedure that is exported from the DLL. }<br> TShowCalendar = function (AHandle: THandle; ACaption: String): TDateTime; StdCall;<br><br> { Create a new exception class to reflect a failed DLL load }<br> EDLLLoadError = class(Exception);<br><br> TMainForm = class(TForm)<br> lblDate: TLabel;<br> btnGetCalendar: TButton;<br> procedure btnGetCalendarClick(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> { Attempt to load the DLL }<br> LibHandle := LoadLibrary('CALENDARLIB.DLL');<br> try<br> { If the load failed, LibHandle will be zero.<br> If this occurs, raise an exception. }<br> if LibHandle = 0 then<br> raise EDLLLoadError.Create('Unable to Load DLL');<br> { If the code makes it here, the DLL loaded successfully, now obtain<br> the link to the DLL's exported function so that it can be called. }<br> @ShowCalendar := GetProcAddress(LibHandle, 'ShowCalendar');<br> { If the function is imported successfully, then set lblDate.Caption to reflect<br> the returned date from the function. Otherwise, show the return raise<br> an exception. }<br> if not (@ShowCalendar = nil) then<br> lblDate.Caption := DateToStr(ShowCalendar(Application.Handle, Caption))<br> else<br> RaiseLastWin32Error; <br> finally<br> FreeLibrary(LibHandle); // Unload the DLL.<br> end;<br>end;<br><br>end.