string AdapterName;
[DllImport("packet.dll", EntryPoint = "PacketGetAdapterNames")]
private static extern bool PacketGetAdapterNames([MarshalAs(UnmanagedType.LPStr)]string sStr, ref int BufferSize);
private void Form1_Load(object sender, EventArgs e)
{
int length = 20;
AdapterName=new string('o',length);
PacketGetAdapterNames(AdapterName, ref length);
this.toolStripStatusLabel1.Text = AdapterName;
}
[DllImport("packet.dll", EntryPoint = "PacketGetAdapterNames")]
private static extern bool PacketGetAdapterNames([MarshalAs(UnmanagedType.LPStr)]string sStr, ref int BufferSize);
private void Form1_Load(object sender, EventArgs e)
{
int length = 20;
AdapterName=new string('o',length);
PacketGetAdapterNames(AdapterName, ref length);
this.toolStripStatusLabel1.Text = AdapterName;
}

本文介绍了一个使用 C# 编写的简单示例程序,该程序通过调用 packet.dll 库中的 PacketGetAdapterNames 函数来获取计算机上的网络适配器名称。文中展示了如何初始化字符串缓冲区,并通过引用传递变量来更新缓冲区大小。
992

被折叠的 条评论
为什么被折叠?



