[prev in list] [next in list] [prev in thread] [next in thread] 

List:       winpcap-bugs
Subject:    [Winpcap-bugs] The function PacketGetAdapterNames can not
From:       gianluca.varenni () cacetech ! com (Gianluca Varenni)
Date:       2008-01-11 1:57:38
Message-ID: 043201c853f5$539b51c0$1a4da8c0 () NELSON2
[Download RAW message or body]

What is the value of length after you call PacketGetAdapterNames?
Marshalling the buffer returned in "an" can be extremely tricky, as it's not 
a string, but rather a concatenation of multiple strings. I would probably 
declare the first parameter of PacketGetAdapterNames as a byte array and 
then do my own marshalling of the strings.

Also, why are you wrapping the Packet API into c#? The Packet API is not 
documented any more and it's subject to change without any notice. The 
blessed API is the pcap API, exposed by wpcap.dll.

Have a nice day
GV


----- Original Message ----- 
From: "? ?" <mailtopaul2003@yahoo.com.cn>
To: <winpcap-bugs@winpcap.org>
Sent: Saturday, January 05, 2008 5:13 PM
Subject: [Winpcap-bugs] The function PacketGetAdapterNames can not returnthe 
adapters' name


> I'm trying to use C#. In my program, I tried to call
> the function which called PacketGetAdapterNames in
> packet.dll, the function could return true, and the
> param which called BufferSize was changed, but the
> adapternames wasn't changed. The following is my code:
>
>    public partial class Form1 : Form
>    {
>
> [DllImport("packet.dll",EntryPoint="PacketGetAdapterNames",CharSet=CharSet.Ansi)]
>        public static extern bool
> PacketGetAdapterNames([MarshalAs(UnmanagedType.LPStr)]string
> sStr, ref int BufferSize);
>
>        public Form1()
>        {
>            InitializeComponent();
>        }
>
>        private void Form1_Load(object sender,
> EventArgs e)
>        {
>            bool b = false;
>            int length = 5;
>            string an = new string('0',length);
>            b = PacketGetAdapterNames(an, ref length);
>            NetworkInterface[] ni =
> NetworkInterface.GetAllNetworkInterfaces();
>            label1.Text = an;
>        }
>    }
>
> After runing, the variables b is true, and the length
> is 242, the an is still "00000". What's wrong with my
> code, please help me, thanks!
>
>
>      ___________________________________________________________
> ???????????????????
> http://cn.mail.yahoo.com/gc/index.html?entry=5&souce=mail_mailletter_tagline
> _______________________________________________
> Winpcap-bugs mailing list
> Winpcap-bugs@winpcap.org
> https://www.winpcap.org/mailman/listinfo/winpcap-bugs 

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic