我在dll里这样定义一个函数:
function funa(m:pchar):string;stdcall;
//返回值为pchar则无法通过编译,why?
begin
showmessage(m);
result:=m+'a';
end;
我在引用这个函数时出异常错误:
procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.text:=funa(label1.caption);
end;以上出错的关键是result:=m+'a';我改为'a'+m;也出错,
而'a'+'a'则没问题,可能是字符串结束符导致的问题吧,
这种相加的形式好象只有调用dll才出错,我觉得是定义时
的类型或引用时的声明有问题,请有经验的兄台讲解一下。
function funa(m:pchar):string;stdcall;
//返回值为pchar则无法通过编译,why?
begin
showmessage(m);
result:=m+'a';
end;
我在引用这个函数时出异常错误:
procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.text:=funa(label1.caption);
end;以上出错的关键是result:=m+'a';我改为'a'+m;也出错,
而'a'+'a'则没问题,可能是字符串结束符导致的问题吧,
这种相加的形式好象只有调用dll才出错,我觉得是定义时
的类型或引用时的声明有问题,请有经验的兄台讲解一下。
{ 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. }