- Safe Removal in service context
- Posted by Anthony Rios on December 16th, 2003
Hello all,
I have developed a simple application which loads and accesses a
mass-storage device in 2k/XP. Now, I would like to
transfer that code over to a service. Everything seems to have transferred
well except for the safe removal code. It seems
the call to CM_Request_Device_Eject() was failing due to the lack of
interactive logon. After some research, I found a
suggestion to use CM_Query_And_Remove_SubTree() because it does not do the
interactive logon check. After trying
this, I now get code 0x34 (CR_CALL_NOT_IMPLEMENTED?) returned from
CM_Query_And_Remove_SubTree().
Any ideas of what I can do here? The problem is simple: How can I perform
a safe removal from a service?
Thanks for you attention.
Tony
- Posted by Maxim S. Shatskih on December 16th, 2003
On each open handle to a device, call RegisterDeviceNotification(
DBT_DEVTYP_HANDLE ). See the HIDCLIENT (or is it HCLIENT?) sample in the DDK
for sample code.
After this, when somebody will like to shut down or disconnect the storage
device, you will receive SERVICE_CONTROL_DEVICEEVENT to your service HandlerEx
routine. In this case, do the preparation work for the about-to-be-lost device,
then close the handle.
You can also try to veto the device removal, but on some buses - like USB -
there are no physical means of doing this. So, do not bother vetoing.
Vetoing Disable request for a CD or hard disk will result in Device Manager
suggesting to reboot :-) also nasty.
--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com
"Anthony Rios" <arios@avionica.com> wrote in message
news:XrydnUC7VMQxH0KiRVn-jw@netrox.net...
- Posted by Anthony Rios on December 17th, 2003
Maxim,
Thank you for your response. You did, in fact, answer my question
as to how to accomplish a safe removal of the mass storage device
from within a service context. However, it seems I have asked the
wrong question.
What I am having trouble with is the
CM_Query_And_Remove_SubTree() function call. I keep getting
0x34 (CR_CALL_NOT_IMPLEMENTED?) returned. I have not
found any documentation on what CR_CALL_NOT_IMPLEMENTED
means and so I have not had any luck fixing this problem.
Can someone explain what CR_CALL_NOT_IMPLEMENTED means?
I might be able to fix it if I knew what it meant.
Thanks again.
-Tony.
"Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
news:eP9G00CxDHA.3216@TK2MSFTNGP11.phx.gbl...
- Posted by Jim Cavalaris [MS] on December 18th, 2003
on Windows 2000, the ANSI versions of CM_Query_And_Remove_SubTree
(CM_Query_And_Remove_SubTreeA, CM_Query_And_Remove_SubTree_ExA)
were not implemented; they are available only on Windows XP and
later.
the Unicode versions of these routines (CM_Query_And_Remove_SubTreeW,
CM_Query_And_Remove_SubTree_ExW) are available on Windows 2000
and later.
for a solution that works on both Windows 2000, Windows XP, and later,
compile your code with UNICODE defined so that the Unicode versions of
all routines are implicitly used, or explicitly call the Unicode
versions of these functions yourself.
hope this helps,
jim.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Anthony Rios" <arios@avionica.com> wrote in message
news:-9KdnWLRLvT78H2iRVn-tw@netrox.net...
- Posted by Anthony Rios on December 18th, 2003
Jim,
Forcing the use of CM_Query_And_Remove_SubTreeW worked!
Thanks for the info. For some reason, I think I remember not being
able to compile this..but it does now!
Thanks again.
----------------------------------------------------------------------
Anthony Rios 786.544.1137
Computer Engineer arios@avionica.com
Avionica, Inc.
http://www.avionica.com
---------------------------------------------------------------------
"Jim Cavalaris [MS]" <jamesca@online.microsoft.com> wrote in message
news:3fe17ad0$1@news.microsoft.com...