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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. FindFirstUrlCacheEntry problem

FindFirstUrlCacheEntry problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 Posts 3 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.
  • S Offline
    S Offline
    Spiritofamerica
    wrote on last edited by
    #1

    hello can someone please tell me what is wrong with this function I wrote: BOOL scan(char *url2search4) { MessageBox(0,url2search4,"a",MB_OK); INTERNET_CACHE_ENTRY_INFO icei; HANDLE the_cache_handle; unsigned long buffer_size=10324; the_cache_handle =FindFirstUrlCacheEntry(NULL/*search_pattern*/,&icei,&buffer_size); if(the_cache_handle==NULL) { DisplayError(GetLastError()); return FALSE; } while(FindNextUrlCacheEntry(the_cache_handle,&icei,&buffer_size)) { MessageBox(0,icei.lpszSourceUrlName,"uite ce am gasit",MB_OK); if(strstr(icei.lpszSourceUrlName,url2search4)==0) { MessageBox(0,"egal","equal",MB_OK); return TRUE; } } return FALSE; } everything builds ok and runs but I never get to actually find a url even thought when I go to C:\Documents and Settings\[MyUserName].000\Local Settings\Temporary Internet Files I can see it there Similar functions from Wininet.h work, like DeleteUrlCacheEntry No matter what I do the_cache_handle is always NULL and the GetLastError fucntion returns "this parrameter is incorect" here is the Display Error Function also if you think this might help void DisplayError(DWORD dwError ) { LPTSTR lpBuffer = NULL; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpBuffer, 0, NULL ); if(dwError!=0) MessageBox(GetActiveWindow(), lpBuffer, "Error", MB_OK|MB_ICONERROR); LocalFree( lpBuffer ); } Please help thank you in advance

    M M 2 Replies Last reply
    0
    • S Spiritofamerica

      hello can someone please tell me what is wrong with this function I wrote: BOOL scan(char *url2search4) { MessageBox(0,url2search4,"a",MB_OK); INTERNET_CACHE_ENTRY_INFO icei; HANDLE the_cache_handle; unsigned long buffer_size=10324; the_cache_handle =FindFirstUrlCacheEntry(NULL/*search_pattern*/,&icei,&buffer_size); if(the_cache_handle==NULL) { DisplayError(GetLastError()); return FALSE; } while(FindNextUrlCacheEntry(the_cache_handle,&icei,&buffer_size)) { MessageBox(0,icei.lpszSourceUrlName,"uite ce am gasit",MB_OK); if(strstr(icei.lpszSourceUrlName,url2search4)==0) { MessageBox(0,"egal","equal",MB_OK); return TRUE; } } return FALSE; } everything builds ok and runs but I never get to actually find a url even thought when I go to C:\Documents and Settings\[MyUserName].000\Local Settings\Temporary Internet Files I can see it there Similar functions from Wininet.h work, like DeleteUrlCacheEntry No matter what I do the_cache_handle is always NULL and the GetLastError fucntion returns "this parrameter is incorect" here is the Display Error Function also if you think this might help void DisplayError(DWORD dwError ) { LPTSTR lpBuffer = NULL; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpBuffer, 0, NULL ); if(dwError!=0) MessageBox(GetActiveWindow(), lpBuffer, "Error", MB_OK|MB_ICONERROR); LocalFree( lpBuffer ); } Please help thank you in advance

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      The first problem I see is you're not seting the dwStructSize member of your INTERNET_CACHE_ENTRY_INFO struct. You're also telling FindNextUrlCacheEntry() that you are passing in a 10324-byte buffer, but your actual buffer isn't that big (it's just one struct). --Mike-- LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ Strange things are afoot at the U+004B U+20DD

      1 Reply Last reply
      0
      • S Spiritofamerica

        hello can someone please tell me what is wrong with this function I wrote: BOOL scan(char *url2search4) { MessageBox(0,url2search4,"a",MB_OK); INTERNET_CACHE_ENTRY_INFO icei; HANDLE the_cache_handle; unsigned long buffer_size=10324; the_cache_handle =FindFirstUrlCacheEntry(NULL/*search_pattern*/,&icei,&buffer_size); if(the_cache_handle==NULL) { DisplayError(GetLastError()); return FALSE; } while(FindNextUrlCacheEntry(the_cache_handle,&icei,&buffer_size)) { MessageBox(0,icei.lpszSourceUrlName,"uite ce am gasit",MB_OK); if(strstr(icei.lpszSourceUrlName,url2search4)==0) { MessageBox(0,"egal","equal",MB_OK); return TRUE; } } return FALSE; } everything builds ok and runs but I never get to actually find a url even thought when I go to C:\Documents and Settings\[MyUserName].000\Local Settings\Temporary Internet Files I can see it there Similar functions from Wininet.h work, like DeleteUrlCacheEntry No matter what I do the_cache_handle is always NULL and the GetLastError fucntion returns "this parrameter is incorect" here is the Display Error Function also if you think this might help void DisplayError(DWORD dwError ) { LPTSTR lpBuffer = NULL; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpBuffer, 0, NULL ); if(dwError!=0) MessageBox(GetActiveWindow(), lpBuffer, "Error", MB_OK|MB_ICONERROR); LocalFree( lpBuffer ); } Please help thank you in advance

        M Offline
        M Offline
        Mike Dimmick
        wrote on last edited by
        #3

        The INTERNET_CACHE_ENTRY_INFO structure displays two common Windows API features. It contains a structure size member (dwStructSize) for versioning purposes - compatibility can be maintained if further fields are later added. The declared structure also does not completely describe the returned data - in fact the structure is only a header, with more data following on. I think you're getting ERROR_INVALID_PARAMETER because the size isn't recognized, because you haven't initialized it. You'll need to allocate memory dynamically because you don't know how big the cache data will be. Your code probably needs to be something like:

        BOOL scan( char* url2search4 )
        {
        INTERNET_CACHE_ENTRY_INFO* picei = NULL;

        DWORD dwBufferSize = 0;
        
        // Initially using a NULL buffer. This causes FindFirstUrlCacheEntry to tell us
        // how much buffer we need.
        
        HANDLE cacheHandle = FindFirstUrlCacheEntry( NULL, picei, &dwBufferSize );
        BOOL success = FALSE;
        
        // The 'first' entry could have changed between our first call and now, and
        // the new first entry might have a bigger size, so we loop until it tells us
        // we have enough buffer.
        
        while ( cacheHandle == NULL && GetLastError() == ERROR\_INSUFFICIENT\_BUFFER )
        {
            delete\[\] (TCHAR\*) picei;
            picei = (INTERNET\_CACHE\_ENTRY\_INFO\*) new TCHAR\[dwBufferSize\];
        
            // Important: tell the API which version of the structure to use.
        
            picei->dwStructSize = sizeof( INTERNET\_CACHE\_ENTRY\_INFO );
        
            cacheHandle = FindFirstUrlCacheEntry( NULL, picei, &dwBufferSize );
        }
        
        if ( cacheHandle != NULL )
        {
            // For FindFirstFile/FindNextFile I use a do/while
            // loop but this has buffer complications. Loop
            // forever until a break statement is reached.
            // Conceptually it's a do/while loop.
        
            for( ; ; )
            {
                // Handle this entry
        
                // I'm just going to write the URL to the console
                puts( picei->lpszSourceUrlName );
        
                // Read next entry
                // Complicated by the fact that we might need a bigger buffer, therefore
                // the function might return FALSE even if there's more data - so we need
                // to see why it failed, and allocate more buffer if required.
        
                success = FindNextUrlCacheEntry( cacheHandle, picei, &dwBufferSize );
        
                while ( !success && GetLastError() == ERROR\_INSUFFICIENT\_BUFFER )
        
        S 2 Replies Last reply
        0
        • M Mike Dimmick

          The INTERNET_CACHE_ENTRY_INFO structure displays two common Windows API features. It contains a structure size member (dwStructSize) for versioning purposes - compatibility can be maintained if further fields are later added. The declared structure also does not completely describe the returned data - in fact the structure is only a header, with more data following on. I think you're getting ERROR_INVALID_PARAMETER because the size isn't recognized, because you haven't initialized it. You'll need to allocate memory dynamically because you don't know how big the cache data will be. Your code probably needs to be something like:

          BOOL scan( char* url2search4 )
          {
          INTERNET_CACHE_ENTRY_INFO* picei = NULL;

          DWORD dwBufferSize = 0;
          
          // Initially using a NULL buffer. This causes FindFirstUrlCacheEntry to tell us
          // how much buffer we need.
          
          HANDLE cacheHandle = FindFirstUrlCacheEntry( NULL, picei, &dwBufferSize );
          BOOL success = FALSE;
          
          // The 'first' entry could have changed between our first call and now, and
          // the new first entry might have a bigger size, so we loop until it tells us
          // we have enough buffer.
          
          while ( cacheHandle == NULL && GetLastError() == ERROR\_INSUFFICIENT\_BUFFER )
          {
              delete\[\] (TCHAR\*) picei;
              picei = (INTERNET\_CACHE\_ENTRY\_INFO\*) new TCHAR\[dwBufferSize\];
          
              // Important: tell the API which version of the structure to use.
          
              picei->dwStructSize = sizeof( INTERNET\_CACHE\_ENTRY\_INFO );
          
              cacheHandle = FindFirstUrlCacheEntry( NULL, picei, &dwBufferSize );
          }
          
          if ( cacheHandle != NULL )
          {
              // For FindFirstFile/FindNextFile I use a do/while
              // loop but this has buffer complications. Loop
              // forever until a break statement is reached.
              // Conceptually it's a do/while loop.
          
              for( ; ; )
              {
                  // Handle this entry
          
                  // I'm just going to write the URL to the console
                  puts( picei->lpszSourceUrlName );
          
                  // Read next entry
                  // Complicated by the fact that we might need a bigger buffer, therefore
                  // the function might return FALSE even if there's more data - so we need
                  // to see why it failed, and allocate more buffer if required.
          
                  success = FindNextUrlCacheEntry( cacheHandle, picei, &dwBufferSize );
          
                  while ( !success && GetLastError() == ERROR\_INSUFFICIENT\_BUFFER )
          
          S Offline
          S Offline
          Spiritofamerica
          wrote on last edited by
          #4

          thank you mister the code works well except for one thing I don't know how to compare the string I get from the FindNextUrlCacheEntry function with the one I have as a parameter: if I do like this if(strcmpi(picei->lpszSourceUrlName,url2search4)==0) { MessageBox(0,"egal","equal",MB_OK); return TRUE; } I get an unhandeled exception error I also tryed with StrCmpI but it also doesn't work any ideas on how to make this work

          1 Reply Last reply
          0
          • M Mike Dimmick

            The INTERNET_CACHE_ENTRY_INFO structure displays two common Windows API features. It contains a structure size member (dwStructSize) for versioning purposes - compatibility can be maintained if further fields are later added. The declared structure also does not completely describe the returned data - in fact the structure is only a header, with more data following on. I think you're getting ERROR_INVALID_PARAMETER because the size isn't recognized, because you haven't initialized it. You'll need to allocate memory dynamically because you don't know how big the cache data will be. Your code probably needs to be something like:

            BOOL scan( char* url2search4 )
            {
            INTERNET_CACHE_ENTRY_INFO* picei = NULL;

            DWORD dwBufferSize = 0;
            
            // Initially using a NULL buffer. This causes FindFirstUrlCacheEntry to tell us
            // how much buffer we need.
            
            HANDLE cacheHandle = FindFirstUrlCacheEntry( NULL, picei, &dwBufferSize );
            BOOL success = FALSE;
            
            // The 'first' entry could have changed between our first call and now, and
            // the new first entry might have a bigger size, so we loop until it tells us
            // we have enough buffer.
            
            while ( cacheHandle == NULL && GetLastError() == ERROR\_INSUFFICIENT\_BUFFER )
            {
                delete\[\] (TCHAR\*) picei;
                picei = (INTERNET\_CACHE\_ENTRY\_INFO\*) new TCHAR\[dwBufferSize\];
            
                // Important: tell the API which version of the structure to use.
            
                picei->dwStructSize = sizeof( INTERNET\_CACHE\_ENTRY\_INFO );
            
                cacheHandle = FindFirstUrlCacheEntry( NULL, picei, &dwBufferSize );
            }
            
            if ( cacheHandle != NULL )
            {
                // For FindFirstFile/FindNextFile I use a do/while
                // loop but this has buffer complications. Loop
                // forever until a break statement is reached.
                // Conceptually it's a do/while loop.
            
                for( ; ; )
                {
                    // Handle this entry
            
                    // I'm just going to write the URL to the console
                    puts( picei->lpszSourceUrlName );
            
                    // Read next entry
                    // Complicated by the fact that we might need a bigger buffer, therefore
                    // the function might return FALSE even if there's more data - so we need
                    // to see why it failed, and allocate more buffer if required.
            
                    success = FindNextUrlCacheEntry( cacheHandle, picei, &dwBufferSize );
            
                    while ( !success && GetLastError() == ERROR\_INSUFFICIENT\_BUFFER )
            
            S Offline
            S Offline
            Spiritofamerica
            wrote on last edited by
            #5

            this works but it takes up a lot of memory every time this thing completes a cicle the memory usage increases and then after about an hour I get a message from windows telling me that memory is to low I see that you use delete to delete that structure but it doesn't seem to be working because memory usage just keeps getting bigger and bigger Is there no way around this?

            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