下面是程序的代码:
implementation
function mymax(x,y:integer):string;stdcall;
external 'DLL1.dll';{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(mymax(strtoint(edit1.Text),strtoint(edit2.Text)));
end;
下面是DLL的代码:
library DLL1;uses
  SysUtils,
  Classes;function mymax(x,y:integer):string;stdcall;
    begin
      if (x <> 0) and (y <> 0) then
        if x > y then
        result:=inttostr(x)
        else if x < y then
        result:=inttostr(y)
        else
        result:='两个数一样都是:'+inttostr(x);    end;{$R *.res}
exports
  mymax;begin
end.
程序运行后,点击按钮1之后就出现一个正确提示的对话框,然后在对话框点确定之后就出现这样的错误提示:Invalid pointer operation请问一下,问题出在哪

解决方案 »

  1.   

    将返回值String改成Char,或者在uses 中 加入DelphiMM
      

  2.   

    DLL传递String类型的时候会出现错误,仔细看看你创建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. }在你的DLL文件中加上 ShareMem,而且必须在最前边library DLL1;uses
      ShareMem,
      SysUtils,
      Classes;在你的程序Unit里也要加上这个