替你改写一下。  function joinstr(str1:pchar;str2:pchar):pchar;stdcall;
  var
    len1,len2,i:integer;
  begin
    len1:=strlen(str1);
    len2:=strlen(str2);
    GetMem(Result, Len1 + len2 + 1);
    StrPCopy(Result, str1);
    StrCat(Result, str2);
  end;

解决方案 »

  1.   

    txt1,txt2没有分配内存,
    使用AllocMem等函数先分配内存。
      

  2.   

    仔细阅读那段英文注释,然后问自己ShareMem单元我用了吗?
      

  3.   

    to ljbsoft
    我改为
    begin
      getmem(txt1,255);
      getmem(txt2,255);
      moudle:=loadlibrary('unitestr.dll');
      if moudle<>0 then
      begin
        edit3.text:='';
        @joinstr:=getprocaddress(moudle,'joinstr');
        if @joinstr<>nil then
        begin
          txt1:=strpcopy(txt1,edit1.text);
          txt2:=strpcopy(txt2,edit2.text);
          edit3.text:=strpas(joinstr(txt1,txt2));
        end;
      end;
      freelibrary(moudle);
    end;
    后,还是报此行错
    edit3.text:=strpas(joinstr(txt1,txt2));
      

  4.   

    to chechy这样一换后,合并后得到非法的字符串
      

  5.   

    我做了一个和你功能一样的。试过,一切OK。library library1;{ 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 JoinStr(Str1, Str2: PChar): PChar; stdcall;
    begin
      Result := PChar(string(Str1) + string(Str2))
    end;exports
    JoinStr;begin
    end.unit Unit11;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        Edit1: TEdit;
        Edit2: TEdit;
        Edit3: TEdit;
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;function JoinStr(Str1, Str2: PChar): PChar; stdcall; external 'library1.dll';implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
    begin
    Edit3.Text := string(JoinStr(PChar(Edit1.Text), PChar(Edit2.Text)));
    end;end.
      

  6.   

    to chechy谢谢你,上面的程序我试了,ok了
    但你那是静态调用假如我用loadlibrary、getprocaddress来动态调用dll该如何实现?
      

  7.   

    用你自己的方法不行吗?
    对了,定义有些小问题,改为:
    Tjoinstr=function(var str1:pchar;str2:pchar):pchar;stdcall;
      

  8.   

          GetMem(txt1,Length(edit1.text) + 1);
          GetMem(txt2,Length(edit2.text) + 1);
          txt1:=strpcopy(txt1,edit1.text);
          txt2:=strpcopy(txt2,edit2.text);