library Project1;{ 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;function RetCharArray1
Char;begin GetMem(result,255); StrCopy(result,'RetCharArray1');end;procedure RetCharArray2(vRet
Char);begin StrCopy(vRet,'RetCharArray2');end;{$R *.res}exports RetCharArray1, RetCharArray2;beginend.//调用procedure TForm1.Button1Click(Sender: TObject);type TRetCharArray1=function
Char; TRetCharArray2=procedure(vRet
Char);var Call1:TRetCharArray1; Call2:TRetCharArray2; hDLL:THandle; p
Char;begin if not FileExists('Project1.dll') then exit; hDLL:=LoadLibrary('Project1.dll'); try @Call1:=GetProcAddress(hDLL,'RetCharArray1'); if @Call1<>nil then edit1.Text:=Call1; GetMem(p,255); @Call2:=GetProcAddress(hDLL,'RetCharArray2'); if @Call2<>nil then begin Call2(p); edit2.Text:=p; FreeMem(p); end; finally if hDLL>0 then FreeLibrary(hDLL); end;end;最好用第二种方法,因为windows API函数大部分也是用参数返回字符数组,而不是直接以函数名的方式返回字符数组