Click here to Skip to main content
15,886,422 members
Home / Discussions / C#
   

C#

 
GeneralRe: Signing an assembly with a strong name Pin
RadioButton22-Jan-04 10:57
RadioButton22-Jan-04 10:57 
GeneralRe: Signing an assembly with a strong name Pin
Heath Stewart22-Jan-04 11:01
protectorHeath Stewart22-Jan-04 11:01 
GeneralRe: Signing an assembly with a strong name Pin
RadioButton22-Jan-04 11:22
RadioButton22-Jan-04 11:22 
GeneralRe: Signing an assembly with a strong name Pin
Daniel Turini22-Jan-04 11:20
Daniel Turini22-Jan-04 11:20 
GeneralRe: Signing an assembly with a strong name Pin
RadioButton22-Jan-04 11:28
RadioButton22-Jan-04 11:28 
GeneralRe: Signing an assembly with a strong name Pin
Heath Stewart22-Jan-04 11:49
protectorHeath Stewart22-Jan-04 11:49 
GeneralRe: Signing an assembly with a strong name Pin
RadioButton22-Jan-04 12:16
RadioButton22-Jan-04 12:16 
GeneralGetIfTable and DllImport Pin
Julien Delezenne22-Jan-04 10:02
Julien Delezenne22-Jan-04 10:02 
Hello,
I managed to use several network Windows API inside C# code with DllImport (such as GetAdaptersInfo) but the GetIfTable seems to be a little bit different.
My problem is that i need to obtain the data in the MIB_IFROW structure and it gets filled with zeros instead of the corect information.
Here is the source code of a simple console application where the problem occurs:
<br />
using System;<br />
using System.Runtime.InteropServices;<br />
using System.Runtime;<br />
<br />
namespace ConsoleApplication1<br />
{<br />
	public class Win32Import<br />
	{<br />
		public static uint ERROR_NOT_SUPPORTED = 50;<br />
<br />
		public const int MAXLEN_IFDESCR = 256;<br />
		public const int MAXLEN_PHYSADDR = 8;<br />
<br />
		public const int MAX_INTERFACE_NAME_LEN = 256;<br />
<br />
		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]<br />
			public struct MIB_IFTABLE<br />
		{<br />
			public uint dwNumEntries;<br />
			public MIB_IFROW table;<br />
		};<br />
<br />
		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]<br />
			public struct MIB_IFROW<br />
		{<br />
			[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_INTERFACE_NAME_LEN)]<br />
			public string  wszName;<br />
<br />
			public uint    dwIndex;<br />
			public uint    dwType;<br />
			public uint    dwMtu;<br />
			public uint    dwSpeed;<br />
			public uint    dwPhysAddrLen;<br />
<br />
			[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAXLEN_PHYSADDR)]<br />
			public byte[]  bPhysAddr;<br />
<br />
			public uint    dwAdminStatus;<br />
			public uint    dwOperStatus;<br />
			public uint    dwLastChange;<br />
			public uint    dwInOctets;<br />
			public uint    dwInUcastPkts;<br />
			public uint    dwInNUcastPkts;<br />
			public uint    dwInDiscards;<br />
			public uint    dwInErrors;<br />
			public uint    dwInUnknownProtos;<br />
			public uint    dwOutOctets;<br />
			public uint    dwOutUcastPkts;<br />
			public uint    dwOutNUcastPkts;<br />
			public uint    dwOutDiscards;<br />
			public uint    dwOutErrors;<br />
			public uint    dwOutQLen;<br />
			public uint    dwDescrLen;<br />
<br />
			[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAXLEN_IFDESCR)]<br />
			public byte[]  bDescr;<br />
		};<br />
<br />
<br />
		[DllImport("kernel32.dll", EntryPoint = "CopyMemory")] public extern static void<br />
			CopyMemory_Int(<br />
			ref uint Destination,<br />
			ref byte Source,<br />
			int Length<br />
			);<br />
<br />
		[DllImport("kernel32.dll", EntryPoint = "CopyMemory")] public extern static void<br />
			CopyMemory_MibIfrow(<br />
			ref MIB_IFROW Destination,<br />
			ref byte Source,<br />
			int Length<br />
			);<br />
<br />
		[DllImport("iphlpapi.dll")] public extern static uint<br />
			GetIfTable(<br />
			byte[] pIfTable,<br />
			ref uint pdwSize,<br />
			bool bOrder<br />
			);<br />
	}<br />
<br />
<br />
	class Class1<br />
	{<br />
		[STAThread]<br />
		static void Main(string[] args)<br />
		{<br />
			uint nBufLen = 0;<br />
			uint nError;<br />
<br />
			nError = Win32Import.GetIfTable(null, ref nBufLen, true);<br />
			if (nError == Win32Import.ERROR_NOT_SUPPORTED)<br />
			{<br />
				return;<br />
			}<br />
<br />
			byte[] IfTableBuffer = new byte[nBufLen];<br />
			nError = Win32Import.GetIfTable(IfTableBuffer, ref nBufLen, true);<br />
			if (nError != 0)<br />
			{<br />
				return;<br />
			}<br />
<br />
			uint dwNumEntries = 0;<br />
			int byteCount = 0;<br />
<br />
			Win32Import.CopyMemory_Int(ref dwNumEntries, ref IfTableBuffer[byteCount], 4);<br />
			byteCount += 4;<br />
<br />
			Win32Import.MIB_IFROW pIfRow = new Win32Import.MIB_IFROW();<br />
			Win32Import.CopyMemory_MibIfrow(<br />
				ref pIfRow,<br />
				ref IfTableBuffer[byteCount],<br />
				Marshal.SizeOf(pIfRow)<br />
				);<br />
			byteCount += Marshal.SizeOf(pIfRow);<br />
		}<br />
	}<br />
}<br />


If you are familiar with these C# API calls and think you can help me , you're welcome. Many thanks!
GeneralRe: GetIfTable and DllImport Pin
Heath Stewart22-Jan-04 11:09
protectorHeath Stewart22-Jan-04 11:09 
GeneralRe: GetIfTable and DllImport //Thanks Pin
Julien Delezenne22-Jan-04 12:19
Julien Delezenne22-Jan-04 12:19 
GeneralMonthCalendar control selecting multiple dates Pin
Chris Meech22-Jan-04 9:38
Chris Meech22-Jan-04 9:38 
GeneralRe: MonthCalendar control selecting multiple dates Pin
Heath Stewart22-Jan-04 11:53
protectorHeath Stewart22-Jan-04 11:53 
GeneralRe: MonthCalendar control selecting multiple dates Pin
Chris Meech23-Jan-04 2:25
Chris Meech23-Jan-04 2:25 
GeneralRe: MonthCalendar control selecting multiple dates Pin
Heath Stewart23-Jan-04 4:37
protectorHeath Stewart23-Jan-04 4:37 
GeneralRe: MonthCalendar control selecting multiple dates Pin
Chris Meech23-Jan-04 5:04
Chris Meech23-Jan-04 5:04 
QuestionTrying to expand middle panel like in Outlook???? Pin
LongRange.Shooter22-Jan-04 9:07
LongRange.Shooter22-Jan-04 9:07 
AnswerRe: Trying to expand middle panel like in Outlook???? Pin
Heath Stewart22-Jan-04 9:31
protectorHeath Stewart22-Jan-04 9:31 
GeneralRe: Trying to expand middle panel like in Outlook???? Pin
LongRange.Shooter22-Jan-04 10:04
LongRange.Shooter22-Jan-04 10:04 
GeneralBase Control for ToolBox, Solution &amp; Properties &quot;Panels&quot; Pin
RapidFireBill22-Jan-04 9:06
RapidFireBill22-Jan-04 9:06 
GeneralRe: Base Control for ToolBox, Solution &amp; Properties &quot;Panels&quot; Pin
LongRange.Shooter22-Jan-04 9:11
LongRange.Shooter22-Jan-04 9:11 
GeneralFind if input is already MD5 encrypted ! Pin
pahluwalia22-Jan-04 4:08
pahluwalia22-Jan-04 4:08 
GeneralRe: Find if input is already MD5 encrypted ! Pin
Heath Stewart22-Jan-04 4:29
protectorHeath Stewart22-Jan-04 4:29 
Generalnewbie question Pin
bouli22-Jan-04 3:54
bouli22-Jan-04 3:54 
GeneralRe: newbie question Pin
Colin Angus Mackay22-Jan-04 4:07
Colin Angus Mackay22-Jan-04 4:07 
GeneralRe: newbie question Pin
bouli22-Jan-04 4:10
bouli22-Jan-04 4:10 

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.