在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,请问这是什么原因啊
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,请问这是什么原因啊
{ 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. }
pchar是delphi标准...如果不行再换成string试试...string应该是肯定可以的.
Application.Process
然后再试
var
pstr: Pchar;
begin
pstr:='c:\tax';
wooddostotxt(pstr);
end;
var
pstr: Pchar;
begin
pstr:=Pchar('c:\tax');
wooddostotxt(pstr);
end;
1.function wooddostotxt(dir:pchar):integer;stdcall;external 'project1.dll';
====>
function wooddostotxt(dir:pchar):integer;cdecl;external 'project1.dll';2.Dll中的wooddostotxt方法后面用stdCall调用习惯;
开发环境:DELPHI 2005+SP2
软件运行环境:XP SP2