我正在使用代碼轉發端口。此代碼在我的Windows 7上正常工作;但我無法在Windows XP上使用它。使用「HNetCfg.NATUPnP」Ole對象失敗的端口轉發
更新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'.
什麼錯誤信息你好嗎當你忽略例外漢傻笑? – TLama
@TLama,AV(訪問衝突)出現錯誤。 –
你的問題是什麼? –