我正在使用代码转发端口。此代码在我的 Windows 7 上运行良好;但我不能在 Windows XP 上使用它。
问题更新 1(2012-10-17 07:32:00Z)
这是我的源代码:
uses
ActiveX, oleAuto;
Procedure AddUPnPEntry(Port: Integer; const Name: ShortString; LAN_IP: string);
Var
Nat: Variant;
Ports: Variant;
SavedCW: Word;
Begin
if NOT(LAN_IP = '127.0.0.1') then
begin
try
Nat := CreateOleObject('HNetCfg.NATUPnP');
Ports := Nat.StaticPortMappingCollection;
// Error Raized From Here!!!
ShowMessage(inttostr(Ports.count));
Ports.Add(Port, 'TCP', Port, LAN_IP, True, name);
except
ShowMessage('An Error occured with adding UPnP Ports. The ' + name +
' port was not added to the router. Please check to see if your ' +
'router supports UPnP and has it enabled or disable UPnP.');
end;
end;
End;
procedure TForm1.Button2Click(Sender: TObject);
begin
AddUPnPEntry(1234, 'Hello3', '192.168.1.1');
end;
AV 错误信息:
Project Project1.exe raised exception class $C0000005 with message 'access violation at 0x00504876: read of address 0x00000000'.