Problem Accessing IPHLPAPI.DLL from C#

Posted on 2003-03-04
Medium Priority
Last Modified: 2012-06-27
I would appreciate any help in calling GetNetworkParams in IPHLPAPI.DLL using C#.

I am new to C# and windows programing, I come from a Java background and I am unfamiliar with DLL's and stucts.

When I run the code attached below I only get a result code of 87.

The ouput of running the code is:

BufferSize => 100000000
Error => 87

My Test Code:

using System;
using System.Runtime.InteropServices;

namespace test
     public class IpHelperTest
          public const int ERROR_BUFFER_OVERFLOW = 111;

          public static extern long GetNetworkParams(ref FIXED_INFO buf, long cbRequired);

          public struct IP_ADDR_STRING
               long dwNext;  
               String IpAddress;  
               String IpMask;
               long dwContext;

          public struct FIXED_INFO
               String HostName;
               String DomainName;  
               IP_ADDR_STRING CurrentDnsServer;
               IP_ADDR_STRING DnsServerList;  
               long NodeType;  
               String ScopeId;
               long EnableRouting;  
               long EnableProxy;  
               long EnableDns;
          public static void Main()
               long bufferSize = 100000000;
               FIXED_INFO Info = new FIXED_INFO();
               long error = GetNetworkParams(ref Info, bufferSize);

               Console.WriteLine("BufferSize => "+bufferSize);
               Console.WriteLine("Error => "+error);

Question by:JimBean
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

WiB earned 300 total points
ID: 8074364
  For the beginning you should fill out your Info structure with valid data.
For further debugging you can see System Error Codes here:

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month9 days, 20 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question