我已經通過了所有堆棧溢出答案搜索,並且Google或Bing都沒有向我展示任何愛。我需要知道何時在Windows CE設備上連接或斷開網絡電纜,最好是從Compact Framework應用程序中斷開。在精簡框架中檢測'網絡電纜未拔掉'
5
A
回答
3
我意識到我在這裏回答我自己的問題,但它實際上是一個通過電子郵件詢問的問題,實際上我花了很長時間找到答案,所以我在這裏發佈它。
因此,檢測這種情況的一般答案是您必須通過IOCTL調用NDIS驅動程序並告訴它您對通知感興趣。這是通過IOCTL_NDISUIO_REQUEST_NOTIFICATION的值完成的(文檔說這不是在WinMo中支持的,但是文檔是錯誤的)。當然,接收通知並不是那麼直截了當 - 你不會得到一些不錯的回調。相反,您必須啓動一個point to point message queue並將其發送給IOCTL調用,以及您想要的特定通知的掩碼。然後,當某些東西發生變化時(比如電纜被拉出),你會在隊列中得到一個NDISUIO_DEVICE_NOTIFICATION結構(MSDN不正確地說這是僅CE),然後你可以解析它以找到有事件的適配器,以及確切的事件是。
從託管代碼的角度來看,這實際上有很多代碼需要編寫 - CreateFile來打開NDIS,所有的排隊API,通知的結構等等。幸運的是,我已經記下了這個並已將其添加到智能設備框架中。因此,如果您使用SDF,請將通知看起來像這樣:
public partial class TestForm : Form
{
public TestForm()
{
InitializeComponent();
this.Disposed += new EventHandler(TestForm_Disposed);
AdapterStatusMonitor.NDISMonitor.AdapterNotification +=
new AdapterNotificationEventHandler(NDISMonitor_AdapterNotification);
AdapterStatusMonitor.NDISMonitor.StartStatusMonitoring();
}
void TestForm_Disposed(object sender, EventArgs e)
{
AdapterStatusMonitor.NDISMonitor.StopStatusMonitoring();
}
void NDISMonitor_AdapterNotification(object sender,
AdapterNotificationArgs e)
{
string @event = string.Empty;
switch (e.NotificationType)
{
case NdisNotificationType.NdisMediaConnect:
@event = "Media Connected";
break;
case NdisNotificationType.NdisMediaDisconnect:
@event = "Media Disconnected";
break;
case NdisNotificationType.NdisResetStart:
@event = "Resetting";
break;
case NdisNotificationType.NdisResetEnd:
@event = "Done resetting";
break;
case NdisNotificationType.NdisUnbind:
@event = "Unbind";
break;
case NdisNotificationType.NdisBind:
@event = "Bind";
break;
default:
return;
}
if (this.InvokeRequired)
{
this.Invoke(new EventHandler(delegate
{
eventList.Items.Add(string.Format(
"Adapter '{0}' {1}", e.AdapterName, @event));
}));
}
else
{
eventList.Items.Add(string.Format(
"Adapter '{0}' {1}", e.AdapterName, @event));
}
}
}
相關問題
- 1. Wiznet W5100拔出電纜檢測
- 2. 串口電纜被拔出
- 3. 在.NET中檢測HDMI電纜事件?
- 4. 在.Net精簡框架中檢測手指滑動
- 5. 簡單的網絡服務器或網絡的測試框架
- 6. TCP服務器斷開/電纜拔出
- 7. Ninject精簡框架
- 8. 精簡版框架:Timer.Dispose未被阻止
- 9. 檢測頁面是否在網絡攝像頭框架中
- 10. ListViewItem邊框 - 精簡框架
- 11. 精簡框架 - 輕量級GUI框架?
- 12. 在.net精簡框架中設置System.Threading.Thread.CurrentThread.CurrentCulture
- 13. C#精簡框架上Math.Sinh
- 14. C#2.0精簡框架TextBox
- 15. 精簡框架定位
- 16. 在MFC C++中檢測FireWire電纜事件?
- 17. 多線程在c#精簡框架
- 18. .NET精簡框架中的URI操作
- 19. .net精簡框架中的HTTP進度
- 20. .NET精簡框架中的信號燈
- 21. 精簡框架中的深入克隆
- 22. 框架檢測
- 23. 聽取以太網電纜拔出TCP服務器應用程序的事件
- 24. 如何獲取插入/拔出的電纜狀態
- 25. 在多行文本框中降序文本(精簡框架,C#)
- 26. 當網絡電纜插入/無線連接時被通知
- 27. 移除網絡電纜時拋出的DOM異常
- 28. 檢測.NET框架在Windows
- 29. 實體框架4.0和Sql精簡版4.0 - 未實現異常
- 30. 檢測即使沒有電源時電源線已拔出