我现在用delphi编写一个DLL
library UGPS;uses
  SysUtils,Dialogs,Classes;{$R *.res}function GetArray(var s:Array of Byte);stdcall;
begin
  SetLength(s,6);   //这句出错(不兼容的类型)
end;Exports
  GetArray,begin
end.请大家帮忙哦

解决方案 »

  1.   

    function GetArray(Len: Integer): Pointer; stdcall;
    var
      s: array of byte;
    begin
      SetLength(s, Len);
      Result:=s;
    end;小心内存泄漏了哦!
      

  2.   

    library Project2;uses
      SysUtils,Dialogs,Classes;  type
        ss = array of byte;{$R *.res}procedure GetArray(var t: ss); stdcall;
    begin
      SetLength(t,6);   //这句出错(不兼容的类型)
    end;Exports
      GetArray;begin
    end.
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;type
      ByteArray = array of byte;var
      Form1: TForm1;implementation{$R *.dfm}procedure GetArray(var s:ByteArray);stdcall;External 'UGPS.dll';procedure TForm1.Button1Click(Sender: TObject);
    var
      m:ByteArray;
    begin
      GetArray(m);     //调用时出错
    end;end.出现调用时出错的问题
      

  4.   

    unit Unit1;interface
    type
       ss = Array of Byte;function GetArray(var s:ss):Pointer;stdcall;
    implementation
    function GetArray(var s:ss):Pointer;stdcall;
    begin
       SetLength(s,6);
    end;
    end.