开发者

GetExtendedUdpTable not working in Delphi 7

I have made the following function in Delphi 7. UDP_TABLE_OWNER_PID = 5;

  {For UDP}
     UDP_TABLE_OWNER_PID = 5;
    type

       UDP_TABLE_CLASS = Integer;

      PMibUdpRowOwnerPid = ^TMibUdpRowOwnerPid;
        TMibUdpRowOwnerPid  = record//packed record
            dwState     : DWORD;
        dwLocalAddr : DWORD;
  //dwLocalPort : DWORD;
            dwRemoteAddr: DWORD;
 // dwRemotePort: DWORD;
  开发者_运维百科          dwOwningPid : DWORD;
           end;


     PMIB_UDPTABLE_OWNER_PID  = ^MIB_UDPTABLE_OWNER_PID;
     MIB_UDPTABLE_OWNER_PID =record// packed record
        dwNumEntries: DWord;
        table: array [0..ANY_SIZE - 1] OF TMibUdpRowOwnerPid;
         end;

  procedure TFmainViewTCP.ShowCurrentUDPConnections(StatusType:String);
    var
   Error        : DWORD;
   TableSize    : DWORD;
      i            : integer;
   IpAddress    : in_addr;
     RemoteIp     : string;
       LocalIp      : string;
      ver:Integer;
       ProcName:string;
     FExtendedUdpTable : PMIB_UDPTABLE_OWNER_PID;
     lItem:TListItem;  {for displaying the output}
       countRow:Integer;
     begin
      i:=0;
   TableSize := 0;
   countRow:=0;

    Error := GetExtendedUdpTable(nil, @TableSize, False,AF_INET,UDP_TABLE_OWNER_PID, 0);

    if Error <> ERROR_INSUFFICIENT_BUFFER then
     begin
          if Error=ERROR_INVALID_PARAMETER then
          begin
           ShowMessage(IntToStr(Error));//Error code is 87, shown here
          end;

           Exit;
        end;

The code gives error, i cannot figure out why. Help will be appreciated.

Thanks in advance


Here is something to get u started it was easier for me to code something from scratch then to fix your code...

type
  MIB_UDPROW_OWNER_PID = record
    dwLocalAddr: DWORD;
    dwLocalPort: DWORD;
    dwOwningPID: DWORD;
  end;

type
  MIB_UPDATE_TABLE = record
    dwNumEntries: DWORD;
    UDP_TABLE: array [0 .. 0] of MIB_UDPROW_OWNER_PID;
  end;

  PMIB_UPDATE_TABLE = ^MIB_UPDATE_TABLE;

function GetExtendedUdpTable(pUdpTable:Pointer;dwSize:PDWORD;bOrder:Boolean;uAlf:ULONG;TableClass:Integer;Reserved:ULONG):DWORD;stdcall;external 'iphlpapi.dll';

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  PID_ : PMIB_UPDATE_TABLE;
  dwSize:DWORD;
  i: Integer;
begin
  GetExtendedUdpTable(nil,@dwSize,false,2,1,0);
  GetMem(PID_,dwSize);
  GetExtendedUdpTable(PID_,@dwSize,false,2,1,0);
  for i := 0 to PID_^.dwNumEntries - 1 do
    ShowMessage(IntToStr(PID_^.UDP_TABLE[i].dwOwningPID));
end;


Your declaration of MIB_UDPROW_OWNER_PID is incorrect. It does not have the dwState member. That's the cause of the error. Also, there's no dwRemoteAddr, instead you should have dwLocalPort.


The error was that UDP_TABLE_OWNER_PID = 1; instead of 5 as i had set. Also, dwState as David had pointed out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜