views:

199

answers:

1

I have studied the documentation on MSDN, but it doesn't work for me, I am wondering what I'm doing wrong?

My code is as follows, I am trying to filter my IE cache, for example, to get only the cookies:

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <wininet.h>

int main(void) {
    DWORD dwEntrySize;
    DWORD dw;
    LPCTSTR filter = "cookie:";
    INTERNET_CACHE_ENTRY_INFO * entry;
    DWORD MAX_CACHE_ENTRY_INFO_SIZE = 4096;
    HANDLE hCacheDir;
    int nCount=0;
    BOOL ok = FALSE;

    dwEntrySize = MAX_CACHE_ENTRY_INFO_SIZE;
    entry = malloc(dwEntrySize);
    entry->dwStructSize = dwEntrySize;


    printf("Reading IE cache\n");
    hCacheDir = FindFirstUrlCacheEntry(filter, entry, &dwEntrySize);

    if ( hCacheDir ) {
        printf("%ws\n", entry->lpszLocalFileName);
        nCount++;

        do {
            dwEntrySize = MAX_CACHE_ENTRY_INFO_SIZE;
            entry = malloc(dwEntrySize);
            entry->dwStructSize = dwEntrySize;

            ok = FindNextUrlCacheEntry(hCacheDir, entry, &dwEntrySize);
            if (ok && entry->lpszLocalFileName != NULL) {
                printf("%ws\n", entry->lpszLocalFileName);
                nCount++;
            }
        } while ( ok );

        printf("**** end cache, total count: %d\n", nCount);
    } 
    else {
        dw = GetLastError();
        printf("error code: %d\n", dw);
    }

    free(entry);
    FindCloseUrlCache(hCacheDir);
    return 0;
}
A: 

Only one free for so many mallocs in do-while loop.

toru