我在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;
代码出错,我无法弄清楚原因。将不胜感激。
提前致谢
答案 0 :(得分:1)
这是让你开始的事情,我更容易从头开始编码,然后修复你的代码...
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;
答案 1 :(得分:0)
您对MIB_UDPROW_OWNER_PID
的声明不正确。它没有dwState
成员。这就是错误的原因。此外,没有dwRemoteAddr
,而是您应该dwLocalPort
。
答案 2 :(得分:0)
错误是UDP_TABLE_OWNER_PID = 1;而不是我设定的5。此外,dwState正如大卫所指出的那样。