• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1102
  • Last Modified:

Problem Accessing IPHLPAPI.DLL from C#

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;

          [DllImport("IPHLPAPI.DLL")]
          public static extern long GetNetworkParams(ref FIXED_INFO buf, long cbRequired);

          [StructLayout(LayoutKind.Sequential)]
          public struct IP_ADDR_STRING
          {
               long dwNext;  
               String IpAddress;  
               String IpMask;
               long dwContext;
          }

          [StructLayout(LayoutKind.Sequential)]
          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);
          }

     }
}
0
JimBean
Asked:
JimBean
1 Solution
 
WiBCommented:
87 = ERROR_INVALID_PARAMETER
  For the beginning you should fill out your Info structure with valid data.
 
For further debugging you can see System Error Codes here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/system_error_codes.asp
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now