By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,679 Members | 2,602 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,679 IT Pros & Developers. It's quick & easy.

c# interop

P: n/a
Hi
what is wrong with this code:
/*
* Created by SharpDevelop.
* User: Robert
* Date: 2004-12-14
* Time: 22:47
*
* To change this template use Tools | Options | Coding | Edit Standard
Headers.
*/
using System;
using System.Runtime.InteropServices;
namespace iphlpapi
{
public class ip_helper
{
enum Constants {
MAX_INTERFACE_NAME_LEN=256, MAXLEN_PHYSADDR=8,MAXLEN_IFDESCR=256
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct MIB_IFROW
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst
=(int)Constants.MAX_INTERFACE_NAME_LEN)]
public string wszName;
public uint dwIndex;
public uint dwType;
public uint dwMtu;
public uint dwSpeed;
public uint dwPhysAddrLen;
[MarshalAs(UnmanagedType.ByValArray, SizeConst
=(int)Constants.MAXLEN_PHYSADDR)]
public byte[] bPhysAddr;
public uint dwAdminStatus;
public uint dwOperStatus;
public uint dwLastChange;
public uint dwInOctets;
public uint dwInUcastPkts;
public uint dwInNUcastPkts;
public uint dwInDiscards;
public uint dwInErrors;
public uint dwInUnknownProtos;
public uint dwOutOctets;
public uint dwOutUcastPkts;
public uint dwOutNUcastPkts;
public uint dwOutDiscards;
public uint dwOutErrors;
public uint dwOutQLen;
public uint dwDescrLen;
[MarshalAs(UnmanagedType.ByValArray, SizeConst
=(int)Constants.MAXLEN_IFDESCR)]
public byte[] bDescr;
}
[StructLayout(LayoutKind.Sequential)]
public struct MIB_IFTABLE
{
public uint dwNumEntries;
public MIB_IFROW[] table;
}
[DllImport("IPHlpApi.dll")]
public static extern uint GetIfTable(IntPtr pIfTable, ref uint pdwSize, bool
bOrder);
/// <summary>
/// Description of MyClass.
/// </summary>
public ip_helper()
{
}
public int InitGetIfTable()
{
uint size = 0;
GetIfTable(IntPtr.Zero, ref size, false);
IntPtr buf = Marshal.AllocHGlobal((int)size);
GetIfTable(buf, ref size, false);
int numEntries = Marshal.ReadInt32(buf);
int pRows = 4 + (int)buf;
MIB_IFROW[] rows = new MIB_IFROW[(int)numEntries];
for ( int i = 0; i < numEntries; i++ )
{
rows[i] = Marshal.PtrToStructure((IntPtr)pRows, typeof(MIB_IFROW));
pRows += Marshal.SizeOf(typeof(MIB_IFROW));
}
Marshal.FreeHGlobal(buf);
return 1;
}
//
private MIB_IFTABLE m_pfTable;
private ulong m_dwAdapters;
}
}

thanks in advance...
i'm traying to write some network transfers monitor using c#.

Regrads, Robert
Nov 22 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.