Click here to Skip to main content
15,887,585 members
Home / Discussions / C#
   

C#

 
GeneralDataGrid cell Selection & Text selection Pin
stone1984-Mar-03 4:50
stone1984-Mar-03 4:50 
GeneralUsing XML files as a database Pin
TeaTime4-Mar-03 3:33
TeaTime4-Mar-03 3:33 
GeneralRe: Using XML files as a database Pin
Mark Sanders4-Mar-03 9:50
Mark Sanders4-Mar-03 9:50 
GeneralRe: Using XML files as a database Pin
Nick Parker4-Mar-03 18:56
protectorNick Parker4-Mar-03 18:56 
QuestionMultiple Forms: Hot to get Keyboard Input from any form and any Control? Pin
STW4-Mar-03 2:38
STW4-Mar-03 2:38 
GeneralDeleting a row from a datagrid Pin
Yann CK3-Mar-03 23:54
Yann CK3-Mar-03 23:54 
GeneralRe: Deleting a row from a datagrid Pin
Adam Turner5-Mar-03 12:57
Adam Turner5-Mar-03 12:57 
GeneralAccesinng IPHLPAPI.DLL GetNetworkParams() from C# Pin
Member 2680673-Mar-03 22:29
Member 2680673-Mar-03 22:29 
I need to programmatically retrieve IP configuration information using the IP Helper APIs GetNetworkParams() from C#.

Everytime I call the function all I get back is a value of 87

I come from a Java background and I am unfamiliar with both structs and DLL's.

Below is my code, I would appreciate it if someonce code provide me with a working implementation or pointers to what I am doing wrong;)

The results of running the code are

UNKNOWN ERROR => 87
bufferSize => 9999999999999999999
error => 87


using System;
using System.Runtime.InteropServices;

namespace dlltest
{
public class IpHelperTest
{
public const int ERROR_BUFFER_OVERFLOW = 111;

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

public IpHelperTest()
{
ulong bufferSize = 9999999999999999999;

FIXED_INFO Info = new FIXED_INFO();

long error = GetNetworkParams(ref Info, bufferSize);
if(error == ERROR_BUFFER_OVERFLOW)
{
Console.WriteLine("BUFFER OVERFLOW => "+error);
}
else if(error == 0)
{
Console.WriteLine("GOT INFO");
}
else
{
Console.WriteLine("UNKNOWN ERROR => "+error);
}

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

[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()
{
IpHelperTest ipHelperTest = new IpHelperTest();
}
}
}
GeneralWindows XP and Many Many Windows Pin
Adam Turner3-Mar-03 21:29
Adam Turner3-Mar-03 21:29 
GeneralProvideProperty for event property Pin
jclanz3-Mar-03 21:10
jclanz3-Mar-03 21:10 
GeneralData Grid doubt Pin
Smitha Nishant3-Mar-03 19:51
protectorSmitha Nishant3-Mar-03 19:51 
GeneralRe: Data Grid doubt Pin
Peter Kiss4-Mar-03 0:34
Peter Kiss4-Mar-03 0:34 
GeneralRe: Data Grid doubt Pin
A.Wegierski4-Mar-03 0:34
A.Wegierski4-Mar-03 0:34 
GeneralRe: Data Grid doubt - Thanks Pin
Smitha Nishant4-Mar-03 4:21
protectorSmitha Nishant4-Mar-03 4:21 
Generalodd form behavior Pin
grv5753-Mar-03 10:51
grv5753-Mar-03 10:51 
Generalscroll and focus bug Pin
bwells3-Mar-03 9:22
bwells3-Mar-03 9:22 
GeneralHelp: Unable To Copy Data (In Structure) from Unmanged MFC/C++ App to .NET Pin
Gaul3-Mar-03 9:00
Gaul3-Mar-03 9:00 
GeneralSaving Treeview/Listview selections Pin
vlusardi3-Mar-03 7:47
vlusardi3-Mar-03 7:47 
GeneralRegistry and dWord values Pin
codeweenie3-Mar-03 7:36
codeweenie3-Mar-03 7:36 
GeneralRe: Registry and dWord values Pin
leppie3-Mar-03 7:51
leppie3-Mar-03 7:51 
GeneralRe: Registry and dWord values Pin
codeweenie3-Mar-03 8:05
codeweenie3-Mar-03 8:05 
GeneralRe: Registry and dWord values Pin
Paul Riley3-Mar-03 8:31
Paul Riley3-Mar-03 8:31 
GeneralRe: Registry and dWord values Pin
codeweenie3-Mar-03 9:46
codeweenie3-Mar-03 9:46 
GeneralRe: Registry and dWord values Pin
Paul Riley3-Mar-03 11:56
Paul Riley3-Mar-03 11:56 
GeneralRe: Registry and dWord values Pin
leppie3-Mar-03 9:05
leppie3-Mar-03 9:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.