Hi,
Noble Bell said:
Can someone point me in the direction to some c# code for auto-detecting
when a user inserts an sd card into a device?
One technique would be to P/Invoke a function called
RequestDeviceNotifications (documented on MSDN at
http://msdn2.microsoft.com/en-us/library/ms919831.aspx).
The OpenNETCF library has a pre-made wrapper around this API within the
OpenNETCF.Net.DeviceStatusMonitor class. See the documentation at
http://www.opennetcf.com/library/sdf/html/07b50991-2568-a408-0be0-75d435285e09.htm
For the first parameter to the DeviceStatusMonitor constructor you might
like to pass in DeviceStatusMonitor.STORE_MOUNT_GUID which will notify you
whenever a new storage device becomes available to the storeage manager.
Here's an example demonstrating the use of this API.
using OpenNETCF.Net;
DeviceStatusMonitor monitor = new
DeviceStatusMonitor(DeviceStatusMonitor.STORE_MOUNT_GUID, false);
monitor.DeviceNotification += new
DeviceNotificationEventHandler(monitor_DeviceNotification);
monitor.StartStatusMonitoring();
void monitor_DeviceNotification(object sender, DeviceNotificationArgs e)
{
MessageBox.Show(e.DeviceName, e.DeviceAttached ? "attached" :
"disconnected");
}
Hope this helps,
Christopher Fairbairn