在DLL unit里函数是这样的:
function ShowTime():string;stdcall;
implementation
function ShowTime():string;
begin
  Result :=DateToStr(Date());
end;调用的时候是这样写的:
function ShowTime():string;stdcall;external 'DllTest.dll';procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(ShowTime());
end;结果是:显示提示信息后出现这样的提示"Invalid pointer operation."
请大家帮忙看下

解决方案 »

  1.   

    問題大約出在返回類型string上,
    请试着改String为String[100],
    我不想花時間去试,请自己試驗一下。
      

  2.   

    1.不要用string作为dll的参数或返回值,改用pchar
    2.不要在dll中返回字串,改用参数
      

  3.   

    重写一下,供参考,DLL:
    procedure ShowTime(const p:pchar);stdcall;
    begin
      strcopy(p,pchar(DateToStr(Date())));
    end;
    调用:
    procedure TForm1.Button1Click(Sender: TObject);
    var
      p:pchar;
    begin
     getmem(p,100);
     ShowTime(p);
     ShowMessage(p);
     freemem(p);
    end;
      

  4.   

    楼上的兄台,能不能帮我上面的改下,我刚学用DLL,谢谢!
      

  5.   

    在调用的单元中加入
    uses ShareMem;
      

  6.   

    谢谢楼上的兄台,这样的可以,再请教一下,dll中能写函数吗?还是只能用过程?
      

  7.   

    当然可以写函数,不过最好不要返回字串变量,返回integer,double等不会有问题