自己编的一个程序,DLL也是我用delphi2010写的
静态调用dll时没问题,动态调用时出现错误,调用此dll里其它函数没有问题;
如果是函数内部使用了delphi自己的类型,那我传递出来了是shortstring类型啊  源代码:http://l5.yunpan.cn/lk/Q8biwcnFXEpgm
运行formtest.exe 可以看效果delphidll

解决方案 »

  1.   

    不能下载的话联系我 [email protected]
      

  2.   

    问一下:你是否把 shortstring 作为 DLL 外部函数的参数或返回值传递了?
      

  3.   

    sharemem 单元要放在所有单元的最前面,即第一位。
    dll,或引用到该dll的其他所有项目都必须把引用sharememe单元并放在第一位。
    另外要注意使用shortstring时长度截断的问题,shortstring长度为255,不能存入太长的字串,应尽量用pcahr。
      

  4.   


    unit4 做如下修改:
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, {sharemem}; // 去掉sharemem,这个不是放这里的program formtest;uses
      ShareMem,  // 加在这里
      Forms,
      dialogs,
      Unit4 in 'Unit4.pas' {Form4};begin
      Application.Initialize;
      Application.MainFormOnTaskbar := True;
      Application.CreateForm(TForm4, Form4);
      Application.Run;
    end.=====================
    function geturlstringdynamic(): shortstring;
    type
      TFunc = function(x:Integer): shortstring; stdcall; // 你DLL中函数原型必须匹配
    var
      Th: Thandle;
      Tf: TFunc;
      Tp: TFarProc;
    begin  Th := LoadLibraryw('findie.dll');
      @Tf := GetProcAddress(Th, 'GetIEUrl');
      result := Tf(111);
      freelibrary(th);
    end;==================findie.dll 做如下修改:function GetIEUrl(x: integer): shortstring; stdcall;
    var
      DDE: TDdeClientConv;
      bret: boolean;
      presult: pansichar;
      sresult: shortstring;
    begin
      // dde := TDdeClientConv.Create(dde); 改为下面
      dde := TDdeClientConv.Create(nil);
      dde.OpenLink;
      bret := DDE.SetLink('Iexplore', 'WWW_GetWindowInfo');
      if bret then
      begin
        presult := dde.RequestData('0xFFFFFFFF,sURL, sTitle');    sresult := shortstring(presult);
        result := shortstring(geturlstring(sresult));    dde.CloseLink;
        dde.free;
        //result:='15s';
      end
      else
      begin
        result := 'no ie';
      end;
    end;
    最后重写build所有项目
      

  5.   

    library findie;
    uses
      ShareMem,   // 必须第一位,其他引用该dll的项目也一样
      Windows,
      Messages,
      SysUtils 
       ........
      

  6.   

    服了你了
    你看看你的dll函数定义:function GetIEUrl(x:integer):shortstring;stdcall;
    你再看看你的函数调用的地方:type
              TFunc = function():ShortString;
    这个是静态调用的地方:function GetIEUrl():shortstring; stdcall;external 'findie.dll';真能干啊,能写出三种样式来
      

  7.   

    你把函数定义统一下就可以了
    还有楼上的楼上的,shortstring跟sharemem木有关系,请测试再来说话
      

  8.   

    我统一了,都是shortstring的,你看看代码,或者你看哪边没统一的,修改下运行试试 !
      

  9.   

    帖子要结扎了,
    sololie说的很对,给出来的代码也能成功运行,就是更换网页地址后 form窗口多点几次按钮就死了