比如: library dll_fmd;{ 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 EncryStr(Str: String): String;begin str:='dfsd';end; begin end. 怎么调用变量str 在程序里通过showmessage(str); 得出str的内容
先申明,例如,function test(i: Integer): Integer; stdcall; external 'YourDllName' name 'Yourfunname';
library dll_fmd;{ 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 EncryStr(Str: String): String;begin str:='dfsd'; end;//--------------- exports EncryStr; //----------------begin end.
上面写的有点不对,DLL工程中的函数也要加上stdcall function EncryStr(Str: String): String;stdcall; 调用前先声明 function function EncryStr(Str: String): String;stdcall;external 'XXX.dll';
library dll_fmd;{ 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 EncryStr(Str: String): String;begin
str:='dfsd';end;
begin
end.
怎么调用变量str
在程序里通过showmessage(str); 得出str的内容
Result:=str;
在你的函数后面写 Exports EncryStr name 'EncryStr';
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 EncryStr(Str: String): String;begin
str:='dfsd';
end;//---------------
exports
EncryStr;
//----------------begin
end.
function EncryStr(Str: String): String;stdcall;
调用前先声明
function function EncryStr(Str: String): String;stdcall;external 'XXX.dll';
就不用附带BorlandMM.dll
function EncryStr(Str: String):String;stdcall;external 'dll_fmd' name 'EncryStr';
如果DLL是DELPHI写的话,stdcall删掉。DLL里不要用string这种类型,用其他类型代替。