Delphi 德尔菲错误“;E2064左侧不能分配给;64位
我正在尝试将洋红数据包捕获单元编译为64位 当我编译时,我得到了可怕的左边不能被分配到下面的代码行Delphi 德尔菲错误“;E2064左侧不能分配给;64位,delphi,Delphi,我正在尝试将洋红数据包捕获单元编译为64位 当我编译时,我得到了可怕的左边不能被分配到下面的代码行 LongWord(bp) := LongWord(bp) + BPF_WORDALIGN(caplen + hdrlen); 这是因为LongWordcast在64-right中的字节长度不同?有人能帮助正确地修复该行,使其在32位和64位版本中顺利编译吗bp被声明为指针caplen和hdrlen被声明为整数 BPF\u WORDALIGN功能是 function BPF_WORDALIGN(
LongWord(bp) := LongWord(bp) + BPF_WORDALIGN(caplen + hdrlen);
这是因为LongWord
cast在64-right中的字节长度不同?有人能帮助正确地修复该行,使其在32位和64位版本中顺利编译吗<代码>bp被声明为指针caplen
和hdrlen
被声明为整数
BPF\u WORDALIGN
功能是
function BPF_WORDALIGN(X:LongWord) : LongWord;
begin
result := (((X)+(BPF_ALIGNMENT-1))and not(BPF_ALIGNMENT-1));
end;
谢谢你的帮助,让这个工作
以下是故障线路的完整程序(如果有帮助)
function pcap_read( p:PPcap;cnt:integer;CallBack:Tpcap_handler;User:pointer)
: integer;
var cc : Longword;//Counter ?
n : integer;
bp,ep: pointer; //Begin and End Point ?
//bhp : Pbpf_hdr;//pointer to BPF header struct - removed by Lars Peter
hdrlen, //Length of Header
caplen: integer;//Length of captured
begin
if NOT LoadPacketDll then
begin
p.errbuf := 'Cannot load packet.dll';
result:=-1;
exit;
end;
cc := p.cc;
n := 0;
if p.cc = 0 then
begin
// *Capture the Packets*
if PacketReceivePacket(p.adapter,p.packet,TRUE)=false then
begin
// ERROR!
p.errbuf :='Read Error: PacketRecievePacket failed';
result:=-1;
exit;
end;
cc := p.packet.ulBytesReceived;
bp := p.buffer;
end else bp := p.bp;
// Loop through each packet.
ep := ptr(longword(bp)+cc); //move end pointer
while (longword(bp) < longword(ep) ) do
begin
caplen := Pbpf_hdr(bp).bh_caplen;
hdrlen := Pbpf_hdr(bp).bh_hdrlen;
// XXX A bpf_hdr matches apcap_pkthdr.
callback(user,
Ppcap_pkthdr(bp),
ptr(longword(bp)+longword(HdrLen)));
LongWord(bp) := LongWord(bp) + BPF_WORDALIGN(caplen + hdrlen);
inc(n);
if (n >= cnt)and(cnt>0) then
begin
p.bp := bp;
p.cc := longword(ep)-longword(bp);
result := n;
exit;
end;
end;
p.cc := 0;
result:=n;
end;
函数pcap_read(p:PPcap;cnt:integer;回调:Tpcap_处理程序;用户:指针)
:整数;
var-cc:Longword//柜台
n:整数;
bp,ep:指针//起点和终点?
//必和必拓:Pbpf_hdr//指向BPF头结构的指针-已由Lars Peter删除
hdrlen,//头的长度
caplen:整数//捕获长度
开始
如果不加载packetdll,则
开始
p、 errbuf:='无法加载数据包.dll';
结果:=-1;
出口
结束;
cc:=p.cc;
n:=0;
如果p.cc=0,则
开始
//*捕获数据包*
如果PacketReceivePacket(p.adapter,p.packet,TRUE)=false,则
开始
//错误!
p、 errbuf:=“读取错误:packetreceivepacket失败”;
结果:=-1;
出口
结束;
cc:=p.packet.ulbytesserved;
bp:=p.buffer;
结束其他bp:=p.bp;
//循环遍历每个数据包。
ep:=ptr(长字(bp)+cc)//移动结束指针
而(longword(bp)我们不知道什么是bp。可能是指针。演员阵容应为
NativeUInt
。您应该研究周围的代码以确定。可能还有编译器找不到的其他错误。你需要真正理解这一点才能解决它。不要期望在没有学习的情况下就能掌握这一点。好吧,如果有帮助的话,我添加了完整的函数代码?与其让我们做这项工作,您是否考虑过获得理解?您要求我们帮助您编译代码,但这并不是一个有用的目标。您希望代码是正确的。在所有这些转换中,有这么多潜在的错误,而且许多错误是编译器无法检测到的。我一直不明白为什么Embarcadero在已经有(U)Int32
的情况下引入了Fixed(U)Int
。不过,这两种方法都不适合执行此任务。在强制转换指针时,需要使用Native(U)Int
。但就我个人而言,我根本不会向整数投射指针。因为<代码> BP<代码>和<代码> EP<代码>是指针,考虑使用指针算法,例如:代码> EP:=字节(bp)+cc;回调(…,PByte(bp)+HdrLen)。。。bp:=PByte(bp)+BPF_字对齐(caplen+hdrlen)代码>等等。不FixedUInt
。根据我的第一条评论,这是你想要的NativeUInt
。是的,正如我所说,肯定还有很多其他的错误。你需要做一些学习。我知道你不想。我知道你现在希望代码是正确的。但这并不现实。这里没有捷径。