Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Weird problem with FindFirstChangeNotification

Weird problem with FindFirstChangeNotification

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpvisual-studioquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Magnus Westin
    wrote on last edited by
    #1

    The reason for this small test program was that I read on google about a possibility that you could not delete a directory that has a FindFirstChangeNotification watch on it. As it turned out, its no problem at all (at least on WinXP). But I noticed another stranger thing. When I delete the directory in Explorer, the HANDLE is set to signal state and I get a continuous flow of "Something happened". But when I delete the directory in Total Commander (new name for Windows Commander) I get error 5 (Access is denied.) from FindNextChangeNotification. And the program ends. This is not really a question, since the correct implementation should check that the director (or file) you are watching still exists. But what really bothered me were the different results from Explorer and Total Commander. So I wondered if some one else has had this problem or if some one knows why this happens. Here is the small test program I ran while deleting the directory (its written in Visual Studio 6.0 sp5):

    int main( int argc, char* argv[] )
    {
    	HANDLE h = ::FindFirstChangeNotification( "d:\\test\\magnus", FALSE, FILE_NOTIFY_CHANGE_FILE_NAME );
    	if( h == INVALID_HANDLE_VALUE )
    	{
    		std::cout << "Error on FFCN: " << ::GetLastError() << std::endl;
    		return 0;
    	}
    
    
    	std::cout << "Entering loop" << std::endl;
    
    	for( ;; )
    	{
    		DWORD dwWaitState = ::WaitForSingleObject( h, INFINITE );
    		switch( dwWaitState )
    		{
    		case WAIT_OBJECT_0:
    			std::cout << "Something happened" << std::endl;
    			break;
    		case WAIT_ABANDONED:
    			std::cout << "Error WAIT_ABANDONED" << std::endl;
    			break;
    		case WAIT_TIMEOUT:
    			std::cout << "Error WAIT_TIMEOUT" << std::endl;
    			break;
    		default:
    			std::cout << "Error DEFAULT" << std::endl;
    			break;
    		}
    
    		if( dwWaitState != WAIT_OBJECT_0 )
    			break;
    
    		if( ::FindNextChangeNotification( h ) == 0 )
    		{
    			std::cout << "Error on FNCN: " << ::GetLastError() << std::endl;
    			break;
    		}
    	}
    
    	::FindCloseChangeNotification( h );
    	return 0;
    }
    

    Magnus

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups