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

  • Home
  • SEARCH
  • 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 3780854
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:52:04+00:00 2026-05-19T10:52:04+00:00

I have a following problem. I created a PInvoke in a Windows CE .NET

  • 0

I have a following problem. I created a PInvoke in a Windows CE .NET managed project for GetIpForwardTable function. When I call the function in returns the result, but the results are different from the result returned by the route command. There are more entries in the table, Mask and Destination changed places and NextHop is always set to 0.0.0.0

Here is the class (one needs to call IPForwardEntry.GetIpForwardTable()).

public class IPForwardEntry
{
    public enum ForwardType
    {
        Other = 1,
        Invalid = 2,
        Direct = 3,
        Indirect = 4
    }

    public enum ForwardProtocol
    {
        Other = 1,
        Local = 2,
        NetMGMT = 3,
        ICMP = 4,
        EGP = 5,
        GGP = 6,
        Hello = 7,
        RIP = 8,
        IS_IS = 9,
        ES_IS = 10,
        CISCO = 11,
        BBN = 12,
        OSPF = 13,
        BGP = 14,
        NT_AUTOSTATIC = 10002,
        NT_STATIC = 10006,
        NT_STATIC_NON_DOD = 10007
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct MIB_IPFORWARDROW
    {
        public uint dwForwardDest;
        public uint dwForwardMask;
        public int dwForwardPolicy;
        public uint dwForwardNextHop;
        public int dwForwardIfIndex;
        public ForwardType dwForwardType;
        public ForwardProtocol dwForwardProto;
        public int dwForwardAge;
        public int dwForwardNextHopAS;
        public int dwForwardMetric1;
        public int dwForwardMetric2;
        public int dwForwardMetric3;
        public int dwForwardMetric4;
        public int dwForwardMetric5;
    }

    private IPForwardEntry(MIB_IPFORWARDROW forwardRow)
    {
        myForwardRow = forwardRow;
    }

    private MIB_IPFORWARDROW myForwardRow;

    private const int NO_ERROR = 0;

    [DllImport("Iphlpapi.dll")]
    private static extern int CreateIpForwardEntry(MIB_IPFORWARDROW[] pRoute);

    [DllImport("Iphlpapi.dll")]
    private static extern int GetIpForwardTable(MIB_IPFORWARDROW[] pIpForwardTable, ref long pdwSize, bool bOrder);

    public static IPForwardEntry[] GetIpForwardTable()
    {
        long tableSize = 0;
        GetIpForwardTable(null, ref tableSize, true);

        MIB_IPFORWARDROW[] forwardTable = new MIB_IPFORWARDROW[tableSize / Marshal.SizeOf(typeof(MIB_IPFORWARDROW)) + 1];

        long tableSizeOld = tableSize;

        if (GetIpForwardTable(forwardTable, ref tableSize, false) != NO_ERROR)
            throw new SystemException();

        if (tableSizeOld != tableSize)
            throw new SystemException();


        IPForwardEntry[] result = new IPForwardEntry[forwardTable.Length];

        for (int i = 0; i < forwardTable.Length; i++)
            result[i] = new IPForwardEntry(forwardTable[i]);

        return result;

    }

    #region members

    public IPAddress FordwardDestination
    {
        get
        {
            return new IPAddress(myForwardRow.dwForwardDest);
        }
        set
        {
            myForwardRow.dwForwardDest = (uint) value.Address;
        }
    }

    public IPAddress ForwardMask
    {
        get
        {
            return new IPAddress(myForwardRow.dwForwardMask);
        }
        set
        {
            myForwardRow.dwForwardMask = (uint) value.Address;
        }
    }

    public int ForwardPolicy
    {
        get
        {
            return myForwardRow.dwForwardPolicy;
        }
        set
        {
            myForwardRow.dwForwardPolicy = value;
        }
    }

    public IPAddress ForwardNextHop
    {
        get
        {
            return new IPAddress(myForwardRow.dwForwardNextHop);
        }
        set
        {
            myForwardRow.dwForwardNextHop = (uint) value.Address;
        }
    }

    public int ForwardInterfaceIndex
    {
        get
        {
            return myForwardRow.dwForwardIfIndex;
        }
        set
        {
            myForwardRow.dwForwardIfIndex = value;
        }
    }


    public ForwardType ForwrdType
    {
        get
        {
            return myForwardRow.dwForwardType;
        }
        set
        {
            myForwardRow.dwForwardType = value;
        }
    }

    public ForwardProtocol Protocol
    {
        get
        {
            return myForwardRow.dwForwardProto;
        }
        set
        {
            myForwardRow.dwForwardProto = value;
        }
    }


    public int ForwardAge
    {
        get
        {
            return myForwardRow.dwForwardAge;
        }
        set
        {
            myForwardRow.dwForwardAge = value;
        }
    }

    public int ForwardNextHopAS
    {
        get
        {
            return myForwardRow.dwForwardNextHopAS;
        }
        set
        {
            myForwardRow.dwForwardNextHopAS = value;
        }
    }

    public int ForwardMetric1
    {
        get
        {
            return myForwardRow.dwForwardMetric1;
        }
        set
        {
            myForwardRow.dwForwardMetric1 = value;
        }
    }

    public int ForwardMetric2
    {
        get
        {
            return myForwardRow.dwForwardMetric2;
        }
        set
        {
            myForwardRow.dwForwardMetric2 = value;
        }
    }

    public int ForwardMetric3
    {
        get
        {
            return myForwardRow.dwForwardMetric3;
        }
        set
        {
            myForwardRow.dwForwardMetric3 = value;
        }
    }

    public int ForwardMetric4
    {
        get
        {
            return myForwardRow.dwForwardMetric4;
        }
        set
        {
            myForwardRow.dwForwardMetric4 = value;
        }
    }

    public int ForwardMetric5
    {
        get
        {
            return myForwardRow.dwForwardMetric5;
        }
        set
        {
            myForwardRow.dwForwardMetric5 = value;
        }
    }

    #endregion

}
  • 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-05-19T10:52:05+00:00Added an answer on May 19, 2026 at 10:52 am

    GetIpForwardTable doesn’t return an array of MIB_IPFORWARDROW objects, it returns a MIB_IPFORWARDTABLE, that contains an array of rows and the number. So that’s at least one issue. There are likely others as this is not a straightforward P/Invoke set for marshaling.

    For what it’s worth, I’ve already implemented all of this code in the Smart Device Framework, specifically in the OpenNETCF.Net.NetworkInformation.IPRoutingTable class

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not sure if this is possible, but have the following problem... Have created
I have created following stored user defined it gets executed successfully. CREATE FUNCTION spherical_distance1(@a
I have the following problem: I created content type movies and content type actors.
I have a following problem. I have a ListView which returns data from SQL
I have the following problem: I have an HTML textbox ( <input type=text> )
I have the following problem using subversion: I'm currently working on the trunk of
I have the following problem using template instantiation [*]. file foo.h class Foo {
I have the following problem in my Data Structures and Problem Solving using Java
I have the following problem: I open the dialog, open the SIP keyboard to
I have the following problem. If I query values with a keyfigure which is

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.