首页 > 解决方案 > Delphi 错误“E2064 左侧无法分配给”64 位

问题描述

我正在尝试将洋红色数据包捕获单元编译为 64 位。

https://www.magsys.co.uk/delphi/magmonsock.asp

当我编译时,我得到可怕的左侧无法分配给以下代码行

LongWord(bp) := LongWord(bp) + BPF_WORDALIGN(caplen + hdrlen);

这是因为LongWord强制转换是 64 位不同的字节长度,对吗?任何人都可以帮助正确修复该行,以便它在 32 位和 64 位版本中愉快地编译吗?bp被声明为指针。caplen并被hdrlen声明为整数。

BPF_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;

标签: delphi

解决方案


推荐阅读