Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8664849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:20:21+00:00 2026-06-12T17:20:21+00:00

I am using a code for forwarding a port. this code works fine on

  • 0

I am using a code for forwarding a port. this code works fine on My Windows 7; but I can’t use It on Windows XP.

Update 1 For Problem(2012-10-17 07:32:00Z)

This is my source code:

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 Error Message:

Project Project1.exe raised exception class $C0000005 with message 'access violation at 0x00504876: read of address 0x00000000'.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:20:22+00:00Added an answer on June 12, 2026 at 5:20 pm

    If you are getting an access violation, when you access the count property, this means which the IStaticPortMappingCollection interface returned by the IUPnPNAT.get_StaticPortMappingCollection method is nil, this can be caused by many reasons your device doesn’t supports UPnP, The UPnP is not enabled on the device, The UPnP User Interface is not installed/active, and so on.

    Anyway to prevent this kind of exceptions (the access violation) you must check the value returned by the property or method before to use it, in this case you can use the VarIsClear function like so :

    try
      Nat := CreateOleObject('HNetCfg.NATUPnP');
      Ports := Nat.StaticPortMappingCollection;
    
      if not VarIsClear(Ports) then
      begin
        //do something
        ShowMessage(inttostr(Ports.count));
        Ports.Add(Port, 'TCP', Port, LAN_IP, True, name);
      end;
    
    except on E:Exception do
      ShowMessage('An Error occured with adding UPnP Ports. '+E.Message);
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to set port forwarding using c#, but I keep getting this error
using code similar to this Inno Setup for Windows service? on a windows 7
I am using Code Igniter, The HMVC library , and Smarty with this library
I'm using code from other c# app and I can see that in WP7
I am currently using code similar to this: try { // IE ONLY var
This is regarding forwarding POST variables properly in ASP.Net To force all connections use
This is the sample code I am using to hit a URL with fixed
I'm using the code from this article just to try and get something up
We must support some old code that runs using ASIHTTPRequest, but we want the
I'm using Code First with EF 5. Currently I have SPs that return just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.