创建动态库test.dll
其中有函数定义如下:
  function AddStr(instr:string):string;
  begin
  result:='接收到了'+instr;
  end;在客户端调用时为何总是提示“Invalid pointer operation”

解决方案 »

  1.   

    var Libs:THandle;
        str:string;
        fun:function (str: String): integer;
    begin
      Libs:=LoadLibrary(pchar('test.dll'));
      fun:=GetProcAddress(Libs,'AddStr');
      str:=fun(edit1.Text);
      edit2.Text:=inttostr(str);
      ...
      

  2.   

    试试这样:type
      TProc = function (str: String): integer; stdcall;var Libs:THandle;
        str:string;
        modalPro: TProc;
        FPointer: TFarProc;
    begin
      Libs:=LoadLibrary(pchar('test.dll'));
      FPointer:=GetProcAddress(Libs,PChar('AddStr'));
      modalPro := TProc(FPointer);
      modalPro(str);
      FreeLibrary(Libs);
      ...
      

  3.   

    在DLL工程中的Uses中加入ShareMem,放在第一个,因为你传的参数是String 所以一定要用这个单元,并且在调用的工程中也要加,并放在第一个,是调用的工程中,不是单元
    这是解释:
    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.
      

  4.   

    在.ocx中调用test.dll时需要将sharemem放在哪里,单元和工程里都要吗
    都放上以后怎么客户端提示非法操作:(
      

  5.   

    简单的办法,不用调sharemem :-)function AddStr(instr:string):shortstring;