|
Hello!
Try to catch message WM_DEVICECHANGE with DBT_DEVTYP_NET
Hope that it will help.
|
|
|
|
|
hai everybody,
I am doing a project in VC++.
for that i have came accross a trouble.
How to draw a CButton with a backcolor and
a icon on that button.
|
|
|
|
|
|
Interesting issue when using FindFirstChangeNotification and FILE_NOTIFY_CHANGE_FILE_NAME.
I have two threads. Every so often thread A creates a temp file and then uses the MoveFile API command to move the file to a specific folder. Thread B is watching said folder via FindFirstChangeNotification/FILE_NOTIFY_CHANGE_FILE_NAME. When the file appears in the folder, thread B wakes up and processes the file. However, on some PCs, thread B fails to open the file - GetLastError returns 32 - "File in use by another process". I can only imagine that thread B is getting FILE_NOTIFY_CHANGE_FILE_NAME mid-way through the MoveFile. Not sure what to do about this - keep trying to open the file until it succeeds? Tacky. Note I am only getting one FILE_NOTIFY_CHANGE_FILE_NAME notification - so I can't ignore it if the file open fails in the hope I will get another one later.
Stumped. I guess, as this is one app, thread A can call a therad-safe function in thread B and add the file to a list protected by a critical section or something, but this is a fair amount of re-engineering.
Anyone else come across issues like this with FindFirstChangeNotification?
The Rob Blog
|
|
|
|
|
I haven't hit this using FindFirstChangeNotification but I've hit similar problems. I wouldn't keep trying to hit the file until success - as you say, that's tacky.
I've done this only in timed loops - a call to WaitForSingleObject or a call to WaitForMultipleObjects where the loop was intended to run every so often. I've always treated a fail on error 32 as a benign failure and left it to future passes through the loop to handle it.
I notice you say you can't ignore the error because you won't see the notification again. How about launching a thread to monitor the file? You could monitor multiple files in the one thread with reasonable (for your application) sleeps between passes over the locked files.
Rob Manderson
http://www.mindprobes.net
Paul Watson wrote:What sense would you most dislike loosing?
Ian Darling replied.
Telepathy
Then I'd no longer be able to find out everyones dirty little secrets The Lounge, December 4 2003
|
|
|
|
|
Rob, thanks for the response.
I want to keep threads to a minimum as the app already spawns plenty, especially when busy. What I am really after is a reliable way to use FindFirstChangeNotification so I am notified when a new file appears in a folder AND is safe to open!
I think I am going to have to re-engineer the app to allow both threads access to a list of files...
The Rob Blog
|
|
|
|
|
I understand the reluctance to spawn yet another thread. The situation I found myself in was that our application processed a file and then deleted it. Often the file wouldn't delete because some other process had an open handle on it so we had to defer the deletion. My solution was to write a class CDeferredFileDelete that tried to delete the file. If it succeeded well and good. If not, it passed the filename to a service and forgot about it. The service was then responsible for deleting the file at some future time. Hmmm maybe I have an idea for another article
In the situation I'm talking about it was relatively simple - the file was marked for deletion and it didn't much matter when the delete occurred just as long as it did occur. Your situation is somewhat different and I don't really know how (short of a seperate thread) to determine that a new file has appeared and is safe to open.
I think I'd approach it by using the notification to add a file object of some sort to a queue controlled by another thread, and have that thread try to open the file in exclusive mode. If success, close the file and add it to a work queue. If fail, try again in the next pass through the loop. Which is not much different from what I've already suggested
I can't think of a better approach.
Rob Manderson
Paul Watson wrote:What sense would you most dislike loosing?
Ian Darling replied.
Telepathy
Then I'd no longer be able to find out everyones dirty little secrets The Lounge, December 4 2003
|
|
|
|
|
Mmmm. OK, now I have a number of ideas:
1. Change the application so that after calling MoveFile, thread A calls a function that adds the filename to a list (protected by a critical section) and then signals thread B. Thread B wakes up, copies the list contents and processes each file. An even simpler solution would be for thread A to signal thread B - "a new file has been created" and for thread B to enumerate the files in the folder. Any that can't be opened can be ignored as the thread will be signalled for these again soon anyway.
2. Attempt to open the file and if error 32, sleep for a while and try again. However, what if the file beings moved is big (these files could easily be MBs). Would I get a notification when the file is first created or when MoveFile has almost finished?
3. Stick to current scheme but when thread B wakes up, have thread C monitor each file waiting until it can be opened (I guess using a timer). When the file can be opened, add to some list.
I'll experiment. Keeping it simple is usually best, so I think I will start by dropping FindFirstChangeNotification and having thread A set some event that thread B is waiting on when a file has been moved...
Thanks for the help guys.
The Rob Blog
|
|
|
|
|
I'd always go for simplest You can't rely on when the file notification will occur (I think it happens shortly after the file is created for the simple reason that the filesystem has no knowledge about how long the file will be or how long it will be open). Since you can't rely on the file being exclusively available when you get the notification it seems simplest to throw the notification to a monitor thread that will tell your main app when the file really is exclusively available.
Hmmm, after a moments reflection, it seems to me that the only way to be absolutely sure is to have the monitor thread open the file exclusively and throw the HANDLE to the main app thread.
Rob Manderson
Paul Watson wrote:What sense would you most dislike loosing?
Ian Darling replied.
Telepathy
Then I'd no longer be able to find out everyones dirty little secrets The Lounge, December 4 2003
|
|
|
|
|
Wouldn't it just be simpler to create an IOCompletionPort and have thread B wait with a
while (GetQueuedCompletionStatus(pLightningServer->m_hIOCompletionPort,(ULONG *)&pECB,&pUnused,&pOverlapped,INFINITE))<br />
{<br />
if (pOverlapped == (OVERLAPPED *)0xFFFFFFFF)<br />
break;
<br />
}
and then thread A would simply post the file name to the IOCompletionPort when the copy is complete.
Simple, clean, and resource friendly...
onwards and upwards...
|
|
|
|
|
Hmmm you may be right I really have to study up on IO Completion Ports
Rob Manderson
Paul Watson wrote:What sense would you most dislike loosing?
Ian Darling replied.
Telepathy
Then I'd no longer be able to find out everyones dirty little secrets The Lounge, December 4 2003
|
|
|
|
|
They are really pretty straightforward and provide a nice queueing mechanism. The problem is that most people don't think of them unless they are doing actual I/O or thread pooling.
onwards and upwards...
|
|
|
|
|
Hi,
I've met the same issue. My work-around was to Sleep for a small amount of time (say, 100 ms) and retry the file opening only once. Not the nicest way but it seems to work for a long time.
|
|
|
|
|
Hello,
Is it possible to have toolbar on CDialogBar, while my CDialogBar in on CRebar..
the code is as follows
private :
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;
CMyDialogBar m_wndDialogBar;
CReBar r1 ;
CBitmap bitmap;
.
.
.
r1.Create(this);
!m_wndDialogBar.Create(IDD_DIALOGBARX,this)
m_wndToolBar.CreateEx(this, WS_CHILD|TBSTYLE_FLAT | TBSTYLE_TRANSPARENT ));
m_wndToolBar.LoadToolBar(IDR_MAINFRAME);
.
.
r1.AddBar(&m_wndDialogBar, "Second Rebar" ,0,RBBS_GRIPPERALWAYS | RBBS_CHILDEDGE ) ;
r1.AddBar ( &m_wndToolBar, "First Rebar" ,0,RBBS_GRIPPERALWAYS | RBBS_CHILDEDGE ) ;
Now what I want is toolbar on Dialog Bar..while my dialog bar in on Rebar..is it possible, if so How???
regards
Balkrishna Talele
|
|
|
|
|
Dear All,
Pls help me as am a novice to programming especially in VC and don’t know how to mask a voice using FFT. Is there any other way throurh which I can change or mask the voice. Or anyother code through which i be able to mask or change the voice. (.wav file) Or any function which can change the pitch of the wav file.
Pls I need ur help badlly as am running out of time for my final project.
Kind regards
Jenny
|
|
|
|
|
Hello!
Take a look maybe at DirectX API, but probably You will not find interesting functions there. Look at http://sourceforge.net , make some searches over net.
Probably not very helpful, but anyway :P
|
|
|
|
|
Hi ALL.
How i can open doc file in IE Broswer? I don't want to use any scripting language. can any point me in right direction?
Thanks in adavnce
|
|
|
|
|
Maybe you could open a instance of IE programatically along with the URL to the doc file?
The word of the day is legs, let's go back to my house and spread the word
|
|
|
|
|
<br />
ShellExecute(NULL,<br />
"open",<br />
"c:\\program files\\Internet Explorer\\IEXPLORE.EXE",<br />
"c:\\test.doc",<br />
NULL, <br />
SW_SHOWNORMAL); <br />
greatest thing is to do wot others think you cant suhredayan@omniquad.com
|
|
|
|
|
Hi Suhredayan,
When I try to use the ShellExecute() function, Its open a new instance of word and open c:\\test.doc and not in IE Window.
I am using IE6 Browser and having word2000. Does it depends upon version of either IE or Word ??
Again thanks in advanace
AL
|
|
|
|
|
Are you sure you specified 3rd parameter as "IEXPLORER.EXE"
greatest thing is to do wot others think you cant suhredayan@omniquad.com
|
|
|
|
|
Yes,
Here this is what i am doing
ShellExecute(NULL,"open","c:\\program files\\Internet Explorer\\IEXPLORE.EXE",
"c:\\test.doc", NULL, SW_SHOWNORMAL);
Its strange thing that if test.doc is not on the disk, Its gives error Dialog Box cannot find file:///c:/test.doc, MaKe sure that path is correct or Internet address is correct.
Also there is no iexplore.exe process(which is swapn by ShellExecute function) running in task manager.
Thanks once again
AL
|
|
|
|
|
I have a dialog with a listbox control and a edit box, so when the user selects a listbox string the edit box has to be update. my question is, how can I know (which message) that the user has selected a string?
I'm using visual c++ 6.0 without MFC, only winapi32.
thanks
Christian
|
|
|
|
|
|
the link should be
http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/listboxes/usinglistboxes.asp
Sorry About that.
|
|
|
|