I understand that I am answering my own question here, but actually this is a question asked by email, and I really spent a lot of time finding an answer, so I post it here.
, , NDIS IOCTL , . IOCTL_NDISUIO_REQUEST_NOTIFICATION ( , WinMo, ). , - . IOCTL , . , - (, ), NDISUIO_DEVICE_NOTIFICATION ( MSDN , CE) , , , , .
, - CreateFile, NDIS, API , .. , Smart Device Framework. , 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));
}
}
}