library txt;{ Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. }uses SysUtils, Classes;{$R *.res}function ceshi(s : string) : boolean; var t : Tstringlist; begin t :=Tstringlist.Create; t.Add(s); t.SaveToFile('d:/123.txt'); freeandnil(t); result:=true; end; exports ceshi; begin end.
procedure TForm1.Button1Click(Sender: TObject); Type TdllProc=function (s : string) : boolean ;Stdcall; var dllproc: Tdllproc; dllHandle:THandle; begin dllHandle:=LoadLibrary('D:/txt.dll'); If dllHandle<=0 then begin application.MessageBox('调用动态连接库txt.dll失败!','提示',mb_ok+mb_iconinformation); exit; end; @dllProc:=GetProcAddress(dllHandle,'ceshi'); if dllProc('sfsdfsdf') then showmessage('成功'); Freelibrary(dllhandle); end;
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
SysUtils,
Classes;{$R *.res}function ceshi(s : string) : boolean;
var
t : Tstringlist;
begin
t :=Tstringlist.Create;
t.Add(s);
t.SaveToFile('d:/123.txt');
freeandnil(t);
result:=true;
end;
exports
ceshi;
begin
end.
Type TdllProc=function (s : string) : boolean ;Stdcall;
var
dllproc: Tdllproc;
dllHandle:THandle;
begin dllHandle:=LoadLibrary('D:/txt.dll');
If dllHandle<=0 then
begin
application.MessageBox('调用动态连接库txt.dll失败!','提示',mb_ok+mb_iconinformation);
exit;
end;
@dllProc:=GetProcAddress(dllHandle,'ceshi');
if dllProc('sfsdfsdf') then showmessage('成功'); Freelibrary(dllhandle);
end;