检测“网线未插入”在紧凑框架中
我已经浏览了 Stack Overflow 搜索得到的所有答案,但 Google 或 Bing 都没有向我展示任何爱意。我需要知道何时在 Windows CE 设备上(最好是从 Compact Framework 应用程序)连接或断开网络电缆。
I've been through all of the Stack Overflow answers search comes up with, and neither Google or Bing are showing me any love. I need to know when a network cable has been connected or disconnected on a Windows CE device, preferrably, from a Compact Framework application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我意识到我在这里回答了我自己的问题,但这实际上是通过电子邮件提出的问题,而且我实际上花了很长时间才找到答案,所以我将其发布在这里。
因此,关于如何检测到这一点的一般答案是,您必须通过 IOCTL 调用 NDIS 驱动程序并告诉它您对通知感兴趣。这是通过 IOCTL_NDISUIO_REQUEST_NOTIFICATION 值完成的(文档说这不是WinMo 支持,但文档是错误的)。当然,接收通知并不是那么简单 - 您不仅仅是得到一些不错的回电。相反,您必须启动点对点消息队列并发送到 IOCTL 调用中,以及您想要的特定通知的掩码。然后,当发生变化(例如电缆被拉动)时,您将收到 NDISUIO_DEVICE_NOTIFICATION队列上的 结构(MSDN 再次错误地指出这是仅限 CE 的),然后您可以解析该结构以查找发生该事件的适配器以及确切的事件是什么。
从托管代码的角度来看,这实际上需要编写大量代码 - CreateFile 来打开 NDIS、所有排队 API、通知结构等。幸运的是,我已经沿着这条路走了,并且添加了已将其添加到智能设备框架中。因此,如果您使用 SDF,获取通知将如下所示:
I realize I'm answering my own question here, but it was actually a question asked of via email, and I actually spent quite a while finding the answer, so I'm posting it here.
So the general answer for how this is detected is that you have to call down into the NDIS driver via an IOCTL and tell it that you're interested in notifications. This is done with the IOCTL_NDISUIO_REQUEST_NOTIFICATION value (the docs say this is not supported in WinMo, but the docs are wrong). Of course receiving the notifications isn't so straightforward - you son't just get some nice callback. Instead you have to spin up a point to point message queue and send that in to the IOCTL call, along with a mask of which specific notifications you want. Then, when something changes (like the cable is pulled) you'll get an NDISUIO_DEVICE_NOTIFICATION structure (again MSDN incorrectly says this is CE-only) on the queue, which you can then parse to find the adapter that had the event and what the exact event is.
From a managed code perspective, this is actually a lot of code to have to write - CreateFile to open NDIS, all of the queueing APIs, the structures for the notifications, etc. Fortunately, I'd already been down this road and had added it to the Smart Device Framework already. So if you're using the SDF, getting the notifications looks like this: