关于用delphi定义的dll,用pb调用的问题!:
我做图片旋转主要是为PowerBuilder服务,我用delphi编写一个dll,在pb里面调用,结果dll在delphi里面调试通过,但在pb里面有问题:1、是运行后程序无法正常退出,一直占用资源,进程关闭不了。2、是给这个函数两个参数,用来输入源图片名和旋转90以后的图片名,结果在pb中出错。具体程序如下:dll:library Project2;{ 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,  GDIPAPI,   GDIPOBJ,   GDIPUTIL;{$R *.res}function PlusNum(s_name :string;t_name:string) : Integer; stdcall ;
  var
      encoderClsid:   TGUID;
      encoderParameters:   TEncoderParameters;
      transformation:   TEncoderValue;
      Image:   TGPImage;
  begin        Image   :=   TGPImage.Create(s_name);
        GetEncoderClsid('image/jpeg',encoderClsid);
        encoderParameters.Count:=1;
        encoderParameters.Parameter[0].Guid:=EncoderTransformation;
        encoderParameters.Parameter[0].Type_:=EncoderParameterValueTypeLong;
        encoderParameters.Parameter[0].NumberOfValues   :=   1;
        transformation:=EncoderValueTransformRotate90;//旋转90度!
        encoderParameters.Parameter[0].Value:=@transformation;
        image.Save(t_name,encoderClsid,@encoderParameters);
        image.Free;
Result := 1;
end ;
// 导出表
exports  PlusNum ;end.
pb如下:1、声明全局外部函数function integer PlusNum(String  s_name,String  t_name) library "D:\pb\temp\Project2.dll" 2、定义一个窗体,放一个按钮,单击鼠标事件如下:string s_name,t_names_name="c:\1.jpg"
t_name="c:\2.jpg"PlusNum(s_name,t_name)不知道为什么会出错!

解决方案 »

  1.   

    s_name :string;t_name:stringstring用Pchar试试
      

  2.   

    这段写的很清楚的,你仔细看下~
    { 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. }
      

  3.   

    改成Pchar后,程序没有报错,但参数依旧无法正常传递,进程已经无法正常退出!
    甚至我取消参数,把文件名直接写在dll里面,运行正常,但退出后进程无法关闭!
      

  4.   

    你先用delphi程序调用一下dll试试~
      

  5.   

    delphi程序调用,正常的一塌糊涂!!
      

  6.   

    function integer PlusNum(String  s_name,String  t_name) library "D:\pb\temp\Project2.dll" 
    貌似你没加stdcall呀~
      

  7.   

    加上stdcall
    参数用基本类型pchar。
      

  8.   

    呵呵~~,写dll的时候看清楚嘛
    人家boland写好了的
     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.
      

  9.   

    DELPHI的STRING和PB的STRING是不同的,用了STRING ,在PB里就会出错
      

  10.   

    "DELPHI的STRING和PB的STRING是不同的,用了STRING ,在PB里就会出错

    请问,有解决的方法吗!?
      

  11.   

    有Pchar类型.
    另外,我想问你们是怎样发贴的呀?
      

  12.   

    "DELPHI的STRING和PB的STRING是不同的,用了STRING ,在PB里就会出错"
    引用单元第一个加上sharemem,如果在你dll中exports的procedure或function的中有string类型的参数.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.
    这样会使string类型参数传递的时候把string类型当作record或类。
    This applies to all strings passed to and from your DLL--even those that
      are nested in records and classes.
    sharemem单元是在borlndmm.dll中的共享内存管理接口单元,你必须把borlndmm.dll和你的dll一起发布,如果在dll中exports的方法中有string类型的参数
     ShareMem is the interface unit to
      the BORLNDMM.DLL shared memory manager, which must be deployed along
      with your DLL.
    如果想避免使用Borlndmm.dll,使用PChar或ShortString类型的参数代替string类型参数。
    To avoid using BORLNDMM.DLL, pass string information
      using PChar or ShortString parameters.翻译的不好,大概意思应该有了,勉强看吧~~