帮我看一下面的代码,运行后,老是提示.Invalid parameter 不知道那里出错了.
procedure CreateIpEntry(Destination, Mask, Gateway, Metric, aIfNo: string;
Persistent: boolean);
var
Route: TMibIpForwardRow;
Res: DWORD;
IfNo: DWORD;
// The interface number
begin
if Metric = '' then
Metric := '1';
IfNo := DWORD(-1);
if aIfNo = '' then
begin
Res := GetBestInterface(inet_addr(PChar(GateWay)), IfNo);
case Res of
ERROR_SUCCESS: ;
ERROR_NOT_SUPPORTED:
WriteLn(Format(sNotSupported, ['GetBestInterface']));
ERROR_CAN_NOT_COMPLETE:
WriteLn(Format(sCanNotComplete, ['GetBestInterface']));
else
WriteLn(SysErrorMessage(GetLastError));
end;
end
else
IfNo := StrToIntDef(aIfNo, -1);
if IfNo = DWORD(-1) then
begin
WriteLn('Interface is not found.');
Exit;
end;
FillChar(Route, SizeOf(Route), #0);
with Routedo
begin
dwForwardDest := inet_addr(PChar(Destination));
dwForwardMask := inet_addr(PChar(Mask));
dwForwardPolicy := 0;
// Should be zero from Microsoft Help
dwForwardNextHop := inet_addr(PChar(Gateway));
dwForwardIfIndex := IfNo;
dwForwardType := 3;
//The next hop is the final destination (local route).
dwForwardProto := 3;
// PROTO_IP_NETMGMT from Microsoft Help (const in Routprot.h)
dwForwardAge := 0;
dwForwardNextHopAS := 0;
dwForwardMetric1 := StrToIntDef(Metric, 1);
dwForwardMetric2 := DWORD(-1);
dwForwardMetric3 := DWORD(-1);
dwForwardMetric4 := DWORD(-1);
dwForwardMetric5 := DWORD(-1);
end;
Res := CreateIpForwardEntry(Route);
case Res of
NO_ERROR:
if Persistent then
SavePersistentRoute(Destination + ',' + Mask + ',' + Gateway + ',' + Metric, Chr(10));
ERROR_INVALID_PARAMETER:
WriteLn('Invalid parameter');
ERROR_NOT_SUPPORTED:
WriteLn('The IP transport is not configured on the local computer.');
else
WriteLn(SysErrorMessage(GetLastError));
end;
end;