这个函数在C#中如何调用?

youwanna 2004-11-17 03:13:57
C函数:BOOLEAN PacketGetAdapterNames(PTSTR pStr,PULONG BufferSize)

这样写对吗?
[DllImport("packet.dll", EntryPoint="PacketGetAdapterNames")]
private static extern bool PacketGetAdapterNames(string pStr, int BufferSize);

如果写对了,如何来调呢?
如果没有写对,请高手给个demo,谢了
...全文
207 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
youwanna 2004-11-17
  • 打赏
  • 举报
回复
已经调通,接分
youwanna 2004-11-17
  • 打赏
  • 举报
回复
[DllImport("packet.dll", EntryPoint="PacketGetAdapterNames",CharSet=CharSet.Ansi )]
private static extern bool PacketGetAdapterNames([MarshalAs(UnmanagedType.LPStr)]string sStr,ref int BufferSize)
lidawen 2004-11-17
  • 打赏
  • 举报
回复
up
youwanna 2004-11-17
  • 打赏
  • 举报
回复
BOOLEAN PacketGetAdapterNames ( PTSTR pStr,
PULONG BufferSize
)
Retrieve the list of available network adapters and their description.

Parameters:
pStr User allocated string that will be filled with the names of the adapters.
BufferSize Length of the buffer pointed by pStr.

刚看了看,原来是这样子的

youwanna 2004-11-17
  • 打赏
  • 举报
回复
还是报空引用,这个是C源程序

WCHAR adaptername[8192];
adapterlength=sizeof(adaptername);
//返回可以得到的网络适配器列表及描述。
if(PacketGetAdapterNames((char *)adaptername,&adapterlength)==FALSE)
.......

youwanna 2004-11-17
  • 打赏
  • 举报
回复
回:Brunhild()
PacketGetAdapterNames是winpcap里的一个函数


Brunhild 2004-11-17
  • 打赏
  • 举报
回复
不需要用REF,严谨一点大概是这样写吧:
[DllImport("packet.dll", EntryPoint="PacketGetAdapterNames",CharSet=CharSet.Ansi)]
private static extern bool PacketGetAdapterNames([MarshalAs(UnmanagedType.LPStr)]string sStr, int BufferSize);

PULONG是什么类型啊?没见过。
youwanna 2004-11-17
  • 打赏
  • 举报
回复
string str=new string('0', 8092);
PacketGetAdapterNames(ref str,8092);
我是这样调的,报“未将对象引用设置到对象实例”
是不是我调错了?
rroo 2004-11-17
  • 打赏
  • 举报
回复
看看这样行不行
[DllImport("packet.dll", EntryPoint="PacketGetAdapterNames")]
private static extern bool PacketGetAdapterNames(ref string sStr, int BufferSize);
youwanna 2004-11-17
  • 打赏
  • 举报
回复
能给出代码吗?谢谢
Satan0629 2004-11-17
  • 打赏
  • 举报
回复
找个c#中调用api的例子看看就知道了
youwanna 2004-11-17
  • 打赏
  • 举报
回复
自己顶一下
youwanna 2004-11-17
  • 打赏
  • 举报
回复
WCHAR adaptername[8192];
if(PacketGetAdapterNames((char *)adaptername,&adapterlength)==FALSE)
.....

这个是C代码

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧