Unable to unplug the USB device if I open and close any document from USB device from my application

Hi,

I have written a aplication which support specific file format
document say .dat file. By using this application I can open \ read \
write the .dat files. But If I open a .dat file which is present in
USB device and modify the content of a file and close the file
properly then if i try to unplug the USB (without closing my
application) then Windows Vista \ XP will not allow to unplug the USB
device it says "Windows can's stop your Generic volume device....."
message box. To unplug the USB device I have to close my application.

Can anyone please tell me why I am unable to unplug the USB device
without closing my application ?  Is I need to take care any Windows
OS \ registry setting in my application ?

Note: 1. If a .txt file is present in USB device and I open that .txt
file in notepad and modify, save and close the file. Without closing
the notepad application if I unplug the USB device then it will get
unplug.
2. I have written my application using VC++ 8.0 using MFC and allowed
user to select the USB device file by using CFileDialog class.
0
Teju
1/10/2010 5:33:55 PM
vc.mfc 33608 articles. 0 followers. Follow

8 Replies
1440 Views

Similar Articles

[PageSpeed] 37

>I have written a aplication which support specific file format
>document say .dat file. By using this application I can open \ read \
>write the .dat files. But If I open a .dat file which is present in
>USB device and modify the content of a file and close the file
>properly then if i try to unplug the USB (without closing my
>application) then Windows Vista \ XP will not allow to unplug the USB
>device it says "Windows can's stop your Generic volume device....."
>message box. To unplug the USB device I have to close my application.
>
>Can anyone please tell me why I am unable to unplug the USB device
>without closing my application ?

What's your application's current working directory? If that's on the
USB device that would explain the issue. Have a look at the
SysInternals Process Explorer tool, using that you should be able to
identify what handle on the USB device is giving rise to the issue.

Dave
0
David
1/10/2010 10:41:09 PM
When you open the file, your current working directory is set to the directory that
contains the file.  This increases the "activity count" on the device.  As long as your
app has any directory selected on the device, the OS believes that it is going to
potentially do something to that device, and will not allow the device to be removed.

If you automatically change the working directory away from the device, it will annoy the
user.  I don't want to have to keep selecting the device each time.  I believe there is
even a option bit that does not allow the directory to be changed, but I have never
understood if it forbids ANY change to the directory, or merely does not retain the change
after the file dialog closes, but I've never thought it made sense to use it.

So you can open another file and change to a directory on another device.  This means you
will not need to shut the app down.  Most users with pluggable devices have long since
figured this out.

It MIGHT be possible to get the query to remove the device notification in your app, and
it could switch back to, say, "my documents".  I'd investigate that path.  You have to
register the device GUID to get the notifications.
					joe

On Sun, 10 Jan 2010 09:33:55 -0800 (PST), Teju <tejesh.joshi@gmail.com> wrote:

>Hi,
>
>I have written a aplication which support specific file format
>document say .dat file. By using this application I can open \ read \
>write the .dat files. But If I open a .dat file which is present in
>USB device and modify the content of a file and close the file
>properly then if i try to unplug the USB (without closing my
>application) then Windows Vista \ XP will not allow to unplug the USB
>device it says "Windows can's stop your Generic volume device....."
>message box. To unplug the USB device I have to close my application.
>
>Can anyone please tell me why I am unable to unplug the USB device
>without closing my application ?  Is I need to take care any Windows
>OS \ registry setting in my application ?
>
>Note: 1. If a .txt file is present in USB device and I open that .txt
>file in notepad and modify, save and close the file. Without closing
>the notepad application if I unplug the USB device then it will get
>unplug.
>2. I have written my application using VC++ 8.0 using MFC and allowed
>user to select the USB device file by using CFileDialog class.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
Joseph
1/10/2010 11:50:57 PM
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:lnpkk5l6pagchalarbv77m04okqau3jhsg@4ax.com...
> When you open the file, your current working directory is set to the 
> directory that
> contains the file.  This increases the "activity count" on the device.  As 
> long as your
> app has any directory selected on the device, the OS believes that it is 
> going to
> potentially do something to that device, and will not allow the device to 
> be removed.
>
> If you automatically change the working directory away from the device, it 
> will annoy the
> user.  I don't want to have to keep selecting the device each time.  I 
> believe there is
> even a option bit that does not allow the directory to be changed, but I 
> have never
> understood if it forbids ANY change to the directory, or merely does not 
> retain the change
> after the file dialog closes, but I've never thought it made sense to use 
> it.
>

The bit is OFN_NOCHANGEDIR.  It does not prohibit changing the directory, it 
simply changes the current directory back to the original when the dialog is 
closed.  I don't see any problem with using this flag, and using it will 
also fix the user's issue.

-- David
 

0
David
1/11/2010 12:13:59 AM
I was aware of the flag, but didn't really know its meaning.  It does sound useful,
although it violates the user's expectation that the next time the dialog pops up it is
pointing the the most-recently-used directory (it might work if the directory was set as
the default directory on open...in which case, the change-back should still go back to
something like "my documents" or something else neutral).

But it might be the solution.
				joe

On Sun, 10 Jan 2010 16:13:59 -0800, "David Ching" <dc@remove-this.dcsoft.com> wrote:

>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
>news:lnpkk5l6pagchalarbv77m04okqau3jhsg@4ax.com...
>> When you open the file, your current working directory is set to the 
>> directory that
>> contains the file.  This increases the "activity count" on the device.  As 
>> long as your
>> app has any directory selected on the device, the OS believes that it is 
>> going to
>> potentially do something to that device, and will not allow the device to 
>> be removed.
>>
>> If you automatically change the working directory away from the device, it 
>> will annoy the
>> user.  I don't want to have to keep selecting the device each time.  I 
>> believe there is
>> even a option bit that does not allow the directory to be changed, but I 
>> have never
>> understood if it forbids ANY change to the directory, or merely does not 
>> retain the change
>> after the file dialog closes, but I've never thought it made sense to use 
>> it.
>>
>
>The bit is OFN_NOCHANGEDIR.  It does not prohibit changing the directory, it 
>simply changes the current directory back to the original when the dialog is 
>closed.  I don't see any problem with using this flag, and using it will 
>also fix the user's issue.
>
>-- David
> 
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
Joseph
1/11/2010 4:41:50 AM
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:7talk5d5gi794ic4eakf1fr58hvn4gnftr@4ax.com...
> I was aware of the flag, but didn't really know its meaning.  It does 
> sound useful,
> although it violates the user's expectation that the next time the dialog 
> pops up it is
> pointing the the most-recently-used directory (it might work if the 
> directory was set as
> the default directory on open...in which case, the change-back should 
> still go back to
> something like "my documents" or something else neutral).
>
> But it might be the solution.
> joe
>

Yes, my apps stores folder paths for all Open dialogs it puts up and 
initializes the Initial Dir field to this.  But I added the code before 
Windows kept track of that itself, a useful feature.  Speaking of which, 
Windows now remembers the last folder the OpenFile dialog was at on a per 
app basis in the registry.  This doesn't seem to depend on what the current 
directory is, so perhaps even if this flag is set, the next time the dialog 
will pop up to the last used folder.  It would be interesting to try this, 
but as I said my apps already set the initial directory.

-- David
 

0
David
1/11/2010 5:09:52 AM
On Jan 11, 3:41=A0am, David Lowndes <Dav...@example.invalid> wrote:
> >I have written a aplication which support specific file format
> >document say .dat file. By using this application I can open \ read \
> >write the .dat files. But If I open a .dat file which is present in
> >USB device and modify the content of a file and close the file
> >properly then if i try to unplug the USB (without closing my
> >application) then Windows Vista \ XP will not allow to unplug the USB
> >device it says "Windows can's stop your Generic volume device....."
> >message box. To unplug the USB device I have to close my application.
>
> >Can anyone please tell me why I am unable to unplug the USB device
> >without closing my application ?
>
> What's your application's current working directory? If that's on the
> USB device that would explain the issue. Have a look at the
> SysInternals Process Explorer tool, using that you should be able to
> identify what handle on the USB device is giving rise to the issue.
>
> Dave

Hi Dave,
Thanks for reply !!

I checked with the Process explorer and found that after read \ write
operation for .dat files the current working directory was getting set
to USB drive so as Joe and Davids reply I set the OFN_NOCHANGEDIR flag
and it is working fine... now I could able to unplug the USB device
without closing my application...

Thanks for pointing out the exact problem.. :)

- Tejesh
0
Teju
1/11/2010 10:05:07 AM
On Jan 11, 10:09=A0am, "David Ching" <d...@remove-this.dcsoft.com>
wrote:
> "Joseph M. Newcomer" <newco...@flounder.com> wrote in messagenews:7talk5d=
5gi794ic4eakf1fr58hvn4gnftr@4ax.com...
>
> > I was aware of the flag, but didn't really know its meaning. =A0It does
> > sound useful,
> > although it violates the user's expectation that the next time the dial=
og
> > pops up it is
> > pointing the the most-recently-used directory (it might work if the
> > directory was set as
> > the default directory on open...in which case, the change-back should
> > still go back to
> > something like "my documents" or something else neutral).
>
> > But it might be the solution.
> > joe
>
> Yes, my apps stores folder paths for all Open dialogs it puts up and
> initializes the Initial Dir field to this. =A0But I added the code before
> Windows kept track of that itself, a useful feature. =A0Speaking of which=
,
> Windows now remembers the last folder the OpenFile dialog was at on a per
> app basis in the registry. =A0This doesn't seem to depend on what the cur=
rent
> directory is, so perhaps even if this flag is set, the next time the dial=
og
> will pop up to the last used folder. =A0It would be interesting to try th=
is,
> but as I said my apps already set the initial directory.
>
> -- David

Hi Joe, Hi Devid...

Thanks for your reply... it realy helps a lot !!

I set the OFN_NOCHANGEDIR flag with CFileDialog and it works fine..
now I could able to unplug the USB device
without closing my application... before opening the CFileDialog I am
always setting some default path as a working directory so I don't
worry about most-recent-used directory selection though my
application...

- Tejesh

0
Teju
1/11/2010 10:13:58 AM
"Teju" <tejesh.joshi@gmail.com> wrote in message 
news:0bece73d-21d7-4164-86f0-dce7a57454a5@d20g2000yqh.googlegroups.com...
> Hi Joe, Hi Devid...
>
> Thanks for your reply... it realy helps a lot !!
>
> I set the OFN_NOCHANGEDIR flag with CFileDialog and it works fine..
> now I could able to unplug the USB device
> without closing my application... before opening the CFileDialog I am
> always setting some default path as a working directory so I don't
> worry about most-recent-used directory selection though my
> application...
>
> - Tejesh

Glad it works Tejesh!

-- David 

0
David
1/11/2010 12:54:46 PM
Reply:

Similar Artilces:

Unable to open Outlook2003. Error: MAPI unable loading msncon.dll
I am trying to set up Outlook 2003 on home computer but keep getting the following message when trying to open application. MAPI was unable to load the information service msncon.dll. Since I am not open to open, I cannot get to the help feature. Please advise Have you downloaded the latest MSN Connector from their site? Or, if not using it, have you uninstalled it? Try opening Outlook in Safe mode (start->run->outlook.exe /safe) and go into the Advanced options and uncheck it from add-in manager or COM add-ins. --� Milly Staples [MVP - Outlook] Post all replies to the group to ...

Unable to Edit/Add records on Form in a New ADP
I just started playing around with rebuilding a MDB file as an ADP. I built a form and subform from scratch, but I'm unable to edit or add records. SELECT Id, LoadDate, TrailerDOTNumber, SealNumber, SealDate, SealId, LoadLocation, LoadStatus, DispatchStatus, DispatchLocationId, DispatchUserId FROM TrailerActivityHeaders ORDER BY LoadDate Recordset Type: Updatable Snapshot I'm getting the 'This recordset is not updatable' Ideas? Never mind... (Does anyone have a spare bandage btw? I cut my head banging it on the wall due to my stupidity...) "D...

First Time Opening Outlook
I just installed Outlook and when I try to open it, I get a popup message titled "Connecting to Microsoft Exhange Server". The message is, "Your Microsoft Exchange Server is unavailable." and a second popup says, "Configuring Outlook Accounts". The configuation process never does complete. I can even open outlook. Help! Thanks Ross Ross <Ross@discussions.microsoft.com> wrote: > I just installed Outlook and when I try to open it, I get a popup > message titled "Connecting to Microsoft Exhange Server". The message > is, "You...

Unable to open calendar
Folks, i cannot open or view my calendar. When I start Oultook a Pop Up appears saying "Could not read the Calendar" On clicking Ok, the pop up vanishes and nothing happens. If i then go over to my calendar, it says "Cannot display the folder" I have run Oultook Diagnostics and nothing shows up as irregular. I ran the repair function (off my setuo CD) and nothing happened. I also re-installed Outlook and rebooted my comp and nada. When staring in safe mode i also get he same errors. I am using Off 2007, Win 7 TIA, P "phamiltonsmith" <...

unable to download emails and unable to stop synchronization
I am going to try one more time to get this fixed. My Outlook 2003 has been unable to download emails. While it is trying, a small box in the tray section shows up and it states that it is trying to synchronize folders. After a time out time Outlook gives me errors. This is the error message. It has these numbers 0X800CCC15 , or 0X8004210A, or 0X8004210B, which these error messages state that either I did not have enough timeout or look and see if server name is wrong. All of you have given me these suggestions. no joy. Thank you very much however. I went ahead and finally found a sect...

unable to scroll the page
on microsoft office frontpage 2003 - when i up loaded my web pages to my web site www.millertimeauction.com , there is no sroll bar for up & down of page - any help what browser? it scrolls for me in IE8 scroll bar will only appear if it needs to -- ~~~~~~~~~~~~~~~~~~ Rob Giordano Microsoft MVP Expression Web "FrontPage Error" <FrontPageError@discussions.microsoft.com> wrote in message news:EC19C7CE-1C5A-4872-A47B-2C04BD7E96A7@microsoft.com... > on microsoft office frontpage 2003 - when i up loaded my web pages to my > web > s...

Unable to start POP3, NNTP, IMAP4...
Dear all, I'm evaluating to install Exchange 2003. After the installation I find the said protocol haven't been started. I tried to start them in "Servers --> Server Name --> Protocols" but no help. Please comment.... Thanks!! Background: Windows 2003, Exchange 2003, Active Directory DC with all roles of FSMO as it's the first DC in the forest. Thank you very much!! -- Are you boring? Let's come to talk together... ^^ news://news.hk4u.com/hk4u.2hit6 Those services are disabled by default in Exchange 2003. Go to Administrative Tools, Services and enable...

Why can't I open any email jokes that friends send me with excel
I get email from friends that send me jokes to open with micro excel and I can't open them why? 1. Do you have Microsoft Excel installed on your computer? 2. What is the extension of the attachments with the jokes? Is it somejoke.XLS ? I never heard of Excel being a joke transporter but who knows? Gord Dibben MS Excel MVP On Sun, 27 May 2007 13:54:00 -0700, Leona <Leona@discussions.microsoft.com> wrote: >I get email from friends that send me jokes to open with micro excel and I >can't open them why? Its because Excel is only for serious work except, of c...

Unable to conect
Hi, I have set up my email account to work with aol using the guidlines for outlook 2002 but it is still unable to connect. Any suggestions? Thanks. John <John@discussions.microsoft.com> wrote: > I have set up my email account to work with aol using the guidlines > for outlook 2002 but it is still unable to connect. Any suggestions? Since you pay AOL for their service, my suggestion is to ask AOL. -- Brian Tillman ...

Unable to click on charts & unable to create any new charts Excel
Hi Just started using Microsoft Excel 2007 and I seem to have done something that means the chart option is unavailable. The chart section is now grey and all charts I have created are 'locked' I cannot click on them anywhere. I'm working on a project and need it finished by Monday. Do you mean that if you click on a chart it does not get a border to show it is activated and there are no range-finder borders around the data that makes the chart? This is a bit odd. Have you tried a new workbook to see if the problem is with just this one? My advice with all odd things is...

I am unable to send e-mails -unable to download files from IMAP.
Please help. I am so frustrated with this In news:4564BC25-92D9-4094-A598-A23848856E5F@microsoft.com, ajmtextiles <ajmtextiles@discussions.microsoft.com> typed: > Please help. > > I am so frustrated with this I can understand why you might be frustrated, but you've provided no useful information for anyone to go on, so I doubt anyone can help you. When you post in here, always include your version, SP level, and mode (if applicable) of Outlook - you can find this information in Help | About. Also include the type of mail account(s) you use and any other pertinent de...

Fade-in/Fade-out of images in vc++ (Dialog based application)
Hi. I wanted to know how I could go about developing fade-in/fade-out transitions of images in a dialog based mfc application.(I am using CImage class) Regards, Rahul This article talks about that a bit... not using CImage class, but perhaps it will be of some help. http://msdn.microsoft.com/msdnmag/issues/05/12/catwork/default.aspx Tom <rahul.thathoo@gmail.com> wrote in message news:1150436043.652481.162040@p79g2000cwp.googlegroups.com... > Hi. > > I wanted to know how I could go about developing fade-in/fade-out > transitions of images in a dialog based mfc applica...

MSXML6 C++ unable to locate node
Hi, I am new to using the MSXML functions in C++. I found this on MSDN as an example of what I wanted to do, http://msdn2.microsoft.com/en-us/library/ms765465.aspx. I have tried a number of XPATH examples to try and retrieve the "><Code>12455</Code>", but have been unable to do so. The MSDN example works fine. So, I am wondering if it's a namespace issue? Any help would be appreciated. Thanks. Jeff I have changed the code as follows: int _tmain(int argc, _TCHAR* argv[]) { CString sResponse = "<?xml version=\"1.0\" encoding=\"utf...

'OWA was unable to get to your inbox'
Hello, OWA is working fine for everyone on my domain (and has been for years) except for one person. When he logs in it gives the error mentioned above in the subject line. I've checked his exchange account and it doesn't seem to differ from anyone else's... Does anyone know how to solve this problem? Thanks, John Repost in an Exchange group as OWA is a function of Exchange, not Outlook. When you do, include the Exchange/Windows versions, and SP-level for each. -- Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (in...

Unable to display the folder (have I lost my mail?)
I've just transferred all my mail from my mac via IMAP, and rather laboriously set up all my rules to get all my mailing lists in separate folders etc. Outlook has just decided that it can't display the two biggest folders because e:\documents and settings\administrator\local settings \application data\microsoft\outlook\outlook.pst is in use and cannot be accessed. The file does not exist. I assume my mail is gone and I have to go and throw it at the IMAP server again, but could anyone tell me why this has happened and how to stop it from happening again? Is this all on a Mac?...

Unable to display
Hello Background: I using Ex2k. when i connect another mailbox in existing admin mailbox, it give error while i click on that particular mailbox. Error is Unable to display the folder. The information store could not br opened: Can anyone tell what exectally the problem, is this a permision or any thing else. Sudhir /Thanks Hello Sudhir In Exchange 2000 an Exchange Full administrator does not have te right to open an other mailbox by default , you need to add these accounts (or groups) to the Information Store object and give the appropriate permissions (send as + read as Greet Dirk ...

File is saved on opening #4
Dave Peterson Wrote: > I don't have another guess. I've never seen excel do anything lik > this. > > You are sure you opened in Safe mode so that all macros were disabled? > (You do see "safe mode" in excel's title bar, right?)Yes, the title bar says 'Microsoft Excel - Safe Mode'. And all m personal settings are gone so I have to fill in my username and I ge that annoying paperclip that welcomes me to Excel and asks me if I wan to start using Excel etc. :( Dave Peterson Wrote: > One more thing to try (that may not help)... > > Open...

I can't open a word document from outlook
I have office 2007 and cannot open word documents I have received or sent - it just started today. I click on the attachment and a pop comes up saying if I want to make changes to the program, if I say yes it goes to the word program but is just grey without the document there. There are no problems with excel or PowerPoint. "Steven Dear" <StevenDear@discussions.microsoft.com> wrote in message news:0775470C-BB6A-4236-BAF7-4D8C65C14120@microsoft.com... >I have office 2007 and cannot open word documents I have received or sent - > it just started today. I cl...

Unable to close/delete Opporotunities
Running CRM 1.2 on W2k3 std. server and SQL2000 on a different w2k3 std. server. The owner of an opportunity is trying to close it. The following message appear on the screen: "There are are still active or draft quotes associated with this opportunity. These must be closed before the opportunity can be closed" We have not configured the Fiscal Year for our CRM system, and thereby not enabled Quotes. This has worked before, and I can't recall that we have made any changes to the system since. Another odd thing is: If an owner of an opportunity or the Administrator is ...

USB Wireless adapter firewalled-is on exception list
I'm working on a dual boot PC for my daughter. I have a USB wireless-n adapter that for some reason WinXPPro SP3 has decided to firewall. I have the only excutable for it as well as the driver listed in the firewall exceptions list. It worked for a day or two but now WinFirewall seems to think it knows better. What gives? Aside from canning XP boot and go only with the Ubuntu boot. -- Für Elise - Support the Breast Cancer & Heart Foundations ...

What application do I require to open an EPS file?
I have been sent a company logo that has been saved in EPS format. What application is required to open this file? I have Office Professional 2003 and Windows XP. Are there any free downloads available to enable me to open the file? It depends on the format of the .eps. www.irfanview.com will open some, get the plug-ins, it is free. Ghostscript will open all. http://www.cs.wisc.edu/~ghost/ -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "meikles2" <meikles2@discussions.microsoft.com> wrote in message news:DBA9B1...

outlook problem (information store could not be opened)
I cannot start my outlook program. It says that the information store could not be opened. Is there a way to fix this problem. I really need to go in and look at my recent e-mails also. Thanks. Sheldon What version? --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (insert latest virus name here) virus, all mail sent to my personal account will be deleted without reading. After searching google.groups.com and finding no answer, Sheldon asked: | I cannot start my outlook program. It says that the | information store could n...

Opening Attachments in 2003
This is so frustrating! In my line of work, I get numerous attachments of .zip, .doc, .txt and .pdf. I have NAV running and scanning all incoming email. Sometimes, when I right click on the attachment and select "Open" (or double click on the attachment), I get an "Attachment Security Warning" that makes me save the file to the hard drive, which I really don't always want to do. However, sometimes, I can open the file with no problem. Why would I even have a problem with a .txt file? Surely those can't carry viruses, can they? Can I over-ride this? Why...

How do I calculate external values from a closed worksheet
I have just upgraded to Excel 2007 am finding that cells are not recalculating from values in closed worksheets as they did in version 2002. While in the open worksheet, I press F2 and then Enter, and it tells me it can't find the closed worksheet, then I click the file name and it updates the cell, however I have to do this for every cell that has a link to a closed worksheet. I have checked and rechecked the formula in my open worksheet several times and it is typed correctly. Do I have to go through this every time? Or is there some way to get the open worksheet to find the ...

cannot open default email folders. information store cannot be ope
i have deleted and reconfigured my profile more than once but Outlook will not open. I can access my mail online through Cox but it does not contain my personal folders or all of my emails. I am using Vista and Outlook 2007. thank you. Have you inadvertently configured your mail account to connect to an Exchange server? "jnormandin" <jnormandin@discussions.microsoft.com> wrote in message news:F8E95224-8BAD-4B79-9CED-B673D68D16DF@microsoft.com... > i have deleted and reconfigured my profile more than once but Outlook will > not open. I can access my mail onl...