N
newyj
Unregistered / Unconfirmed
GUEST, unregistred user!
这是我的一个测试程序
library PrjDll;
uses
windows, SysUtils, Classes;
{$R *.RES}
function file2char(var Pchar):integer
stdcall;export;
//加不加var 有何区别 ?
//好像结果都正确;
var
fm:Tfilestream;
begin
fm:=Tfilestream.Create('1.txt',fmopenread);
result := fm.size;
//ReallocMem(p,fm.size);
//GlobalReAlloc(integer(@p),GMEM_ZEROINIT ,fm.size);
fm.read(p^,fm.size);
fm.Free;
end;
exports
file2char;
begin
end.
/////调用
procedure TForm1.Button1Click(Sender: TObject);
var
pchar;
isize:integer;
begin
getmem(p,8)
//如果分配的内存比实际需要的大没问题,小了就不行;
//我想知道dll中如何去改变内存大小;好像ReallocMem不行
p[0]:=#0;
isize:=file2char(p);
if isize>0 then
begin
richedit1.Clear;
richedit1.Lines.add(p);
end
else richedit1.Lines.add('dfadfdas');
freemem(p,isize);
p:=nil;
end;
library PrjDll;
uses
windows, SysUtils, Classes;
{$R *.RES}
function file2char(var Pchar):integer
stdcall;export;
//加不加var 有何区别 ?
//好像结果都正确;
var
fm:Tfilestream;
begin
fm:=Tfilestream.Create('1.txt',fmopenread);
result := fm.size;
//ReallocMem(p,fm.size);
//GlobalReAlloc(integer(@p),GMEM_ZEROINIT ,fm.size);
fm.read(p^,fm.size);
fm.Free;
end;
exports
file2char;
begin
end.
/////调用
procedure TForm1.Button1Click(Sender: TObject);
var
pchar;
isize:integer;
begin
getmem(p,8)
//如果分配的内存比实际需要的大没问题,小了就不行;
//我想知道dll中如何去改变内存大小;好像ReallocMem不行
p[0]:=#0;
isize:=file2char(p);
if isize>0 then
begin
richedit1.Clear;
richedit1.Lines.add(p);
end
else richedit1.Lines.add('dfadfdas');
freemem(p,isize);
p:=nil;
end;