srhartone
Wed Mar 12 17:54:03 CDT 2008
I find that API a bit flakey, sometimes it doesn't fire when re-inserting the
card!
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com
"Christopher Fairbairn" wrote:
> Hi,
>
> "Noble Bell" <NobleBell@discussions.microsoft.com> wrote in message
> news:8E41931C-96BC-46CB-9D47-D51B0975D54E@microsoft.com...
> > 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
>
>
>