在DLL文件中写到:
function wooddostotxt(dir:pchar):integer;stdcall;
begin
....
end;
在主程序中写到:
var
  Form1: TForm1;
  dir:array [0..512] of char;implementationfunction wooddostotxt(dir:pchar):integer;stdcall;external 'project1.dll';{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
dir:='c:\tax';
wooddostotxt(dir);
end;这样写出来的程序一直报错,而按F7分步执行到最后也不报错,但是普通执行,程序会出错,出错信息是:access violation at address 00000000,read of address 00000000,请问这是什么原因啊

解决方案 »

  1.   


    { 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. }
      

  2.   

    把stdcall去掉或换成cdcel 试试看...我没有delphi,不能先delphi一下.当你用stdcall时delphi会把delphi的变量转成C语言也就是windows标准去call和返回值...
    pchar是delphi标准...如果不行再换成string试试...string应该是肯定可以的.
      

  3.   

    dir:pchar 里的处理问题,内存分配释放问题。
      

  4.   

    在DLL函数最后一行试者加入
    Application.Process
    然后再试
      

  5.   

    dll和主程序都加入ShareMem单元试试
      

  6.   

    procedure TForm1.FormCreate(Sender: TObject);
    var
      pstr: Pchar;
    begin
      pstr:='c:\tax';
      wooddostotxt(pstr);
    end;
      

  7.   

    procedure TForm1.FormCreate(Sender: TObject);
    var
      pstr: Pchar;
    begin
      pstr:=Pchar('c:\tax');
      wooddostotxt(pstr);
    end;
      

  8.   

    两种方法,试试看:
    1.function wooddostotxt(dir:pchar):integer;stdcall;external 'project1.dll';
    ====>
    function wooddostotxt(dir:pchar):integer;cdecl;external 'project1.dll';2.Dll中的wooddostotxt方法后面用stdCall调用习惯;
      

  9.   

    很悲惨,以上各位的方法都试过了,还是出错。真不知道是什么原因了。
    开发环境:DELPHI 2005+SP2
    软件运行环境:XP SP2