问题
I m making windows mobile application, it refers some DLL's but i have some problem here. Imagine my application is installed in storage card related DLL's present in Storage card only, if i launch application it refers some of DLL, now i will remove the storage card, still my application will be running,it will not quit only ultimately it leads to restart of my mobile device.. i do get the divice card remove notification but its in DLL and its c++ code.. if card is removed no DLL will be present in storage card, i dont even get the notification also in c# i dont no how to get the card removed notification in c#. how to handle these scenarios please let me know.
Thanks
回答1:
You can use the function SHChangeNotifyRegister to WM_FILECHANGEINFO message.
After you subscribe, you will be receiving events with ids such as SHCNE_DRIVEREMOVED
or SHCNE_MEDIAREMOVED
, so you can trigger some actions when storage card is removed.
To use native functions from the compact framework, use P/Invoke.
回答2:
Since you just absolutely have to have the source (just like you must have it for the Compact Framework itself and the OS too) and since $50 seems to be too steep for you to get the source for the SDF, here's my donation to you. This is right from the SDF code base (for anyone wondering, I own it, so I'm not violating any license):
public static Guid STORE_MOUNT_GUID = new Guid(_STORE_MOUNT_GUID);
internal const string _STORE_MOUNT_GUID =
"{C1115848-46FD-4976-BDE9-D79448457004}";
[DllImport("coredll.dll", SetLastError = true)]
private static extern IntPtr RequestDeviceNotifications(
byte[] devclass, IntPtr hMsgQ, bool fAll);
[DllImport("coredll.dll", SetLastError = true)]
private static extern bool StopDeviceNotifications(IntPtr h);
The Queue pointer can be retrieved using Daniel Moth's P2P queue implementation (though it has known bugs that are fixed in te SDF). I'm not posting the SDF implementation because it's way too long for a post.
At this point, it becomes as simple as this:
public void StartStatusMonitoring()
{
if (!Active)
{
// Create a point-to-point message queue to get the notifications.
m_p2pmq = new P2PMessageQueue(true);
m_p2pmq.DataOnQueueChanged += new EventHandler(p2pmq_DataOnQueueChanged);
// Ask the system to notify our message queue when devices of
// the indicated class are added or removed.
m_requestHandle = RequestDeviceNotifications(m_deviceClass.ToByteArray(),
m_p2pmq.Handle, m_fAll);
}
}
I'm believe that, armed with this much info and the fact that your time has no intrinsic value, that you can string all of this together for a solution.
EDIT1
I should add to this that adding all of this code is not going to fix your issue 100%. If the code that contains this "fix" has not been JITted, or the JITted code has been pitched, and the IL for it resides in a page that is not in RAM when the storage card gets pulled, the device is still going to puke. This is true whether the code is "in" you running application code or in a separate assembly, so your belief that you have to have the source for this is erroneous.
Adding this fix certainly descreases the window of oppotunity for the bug to appear, but since the chance will still exist, and since Murphy's law certainly applies to software rollouts, you can almost guarantee that this is still going to happen in the field.
回答3:
Take a look at this article: (link). Search for Detecting the Status of Removable Storage Devices. I think this is what you are looking for.
回答4:
If you don't want to use OpenNETCF (not sure why you need the source code), the API call you need to use is RequestDeviceNotifications, and you will need to pass it a handle of a msg queue that is created by calling CreateMsqQueue.
Documentation is here
You will need to P/Invoke these calls from your managed code to register for the notification and then wait on an event for messages to arrive in the queue.
回答5:
If you have your app installed on a user removable storage card you will just wind up in a world of hurt. Strongly warn or outright forbid installation on removable media.
来源:https://stackoverflow.com/questions/1464510/storage-card-problem-in-windows-mobile