xiaofeng_cxy 2007年04月13日
Dll调用问题,分配内存出错
用一个Dll封装了几个IpHlpApi.dll的函数
然后进行调用时,会报内存ReadError
但如果用exe将封装单元引入,则完全正常,有没有大牛能帮我分析一下???

DllUnit

type
PArpRec = ^TArpRec;
TArpRec = record
Ip: string[15];
Index: Integer;
Mac: array[0..7] of Byte;
end;

function _refreshArpTable: Boolean;
var
i, j: Integer;
dwResult, dwSize: DWORD;
p_arptable: PMibIpNetTable;
p_arprow: PMibIpNetRow;
szTemp: string;
parp: PArpRec;
begin
szTemp := '';
p_arptable := nil;

for i := 0 to _arpTable.Count - 1 do
FreeMem( PArpRec( _arpTable.Objects[i] ) );
_arpTable.Clear;
dwSize := 0;
dwResult := GetIpNetTable(p_arptable, dwSize, False);
// if p_arptable = nil then
//报错的就是这行
p_arptable := AllocMem(dwSize);

try
if NO_ERROR = GetIpNetTable(p_arptable, dwSize, False) then
begin
for i := 0 to p_arptable.dwNumEntries - 1 do
begin
p_arprow := AllocMem(SizeOf(TMibIpNetRow));
ZeroMemory(p_arprow, SizeOf(TMibIpNetRow));
Move(p_arptable^.table[i], p_arprow^, SizeOf(TMibIpNetRow));
parp := AllocMem( SizeOf( TArpRec) );
parp^.Ip := inet_ntoa( in_addr( p_arprow^.dwAddr ) );
parp^.Index := p_arprow^.dwIndex;
for j := 0 to 5 do
parp^.Mac[j] := p_arprow^.bPhysAddr[j];

_arpTable.AddObject(parp^.Ip, TObject( parp ));
end;
end;
finally
// if p_arptable <> nil then
FreeMem(p_arptable);
end;
end;

错误信息:
Access violation at address 014663E2 in module 'Arpwatch.dll' write of address 0147FDCC

在线等待,不胜感谢!!!
...全文
257 点赞 收藏 9
写回复
9 条回复

还没有回复,快来抢沙发~

发动态
发帖子
Windows SDK/API
创建于2007-08-02

798

社区成员

2.2w+

社区内容

Delphi Windows SDK/API
社区公告
暂无公告