I'm working on a DLL that has a dcmp32() function to decompress all compressed NTFS files on a drive. My code seems to be working well, but I was wondering if anyone sees any problems. The main thing I am skeptical about is my usages of realloc().

The dcmp32() function uses an array of pointers to char called megabuffer to store a list of all files found on the hard drive. Then an integer array called uarray stores the positions within the megabuffer that contain files or folders that were successfully decompressed. Note that uarray is defined in the .h file and int *uarray and megabuffer is defined as char **megabuffer;

The report32() is used to find out which files and folders were successfully decompressed. This function is called in a loop until it returns -1. Each time the buffer passed to the function is filled with a file path to a file that was successfully decompressed. Memory freeing is handled by this function too, for megabuffer and uarray.

Here is the code I have for the DLL file:
Code:
#include "dll.h"
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#define ID_LIST 1
#define FILE_DEVICE_FILE_SYSTEM 0x00000009
#define METHOD_BUFFERED 0
#define CTL_CODE2(de,fc,meth,acs)(\
((de)<<16)|((acs)<<14)|((fc)<<2)|(meth)\
)
#define FSCTL_SET_COMPRESSION2 CTL_CODE2(FILE_DEVICE_FILE_SYSTEM,16,METHOD_BUFFERED,FILE_READ_DATA|FILE_WRITE_DATA)
void clean32()
{
    if(uarray!=0)
    {
        free(uarray);
    }
    if(megabuffer!=0)
    {
        unsigned j=0;
        for(j;j<filecount;++j)
        {
            if(megabuffer[j]!=0)
            {
                free(megabuffer[j]);
            }
        }
        free(megabuffer);
    }
}
__declspec (dllexport) int report32(char input[1024])
{
    if(dfiles==0)
    {
        return -1;
    }
    memset(input,0x0,1024);
    if(counter<=(dfiles-1))
    {

        strncpy(input,megabuffer[uarray[counter]],strlen(megabuffer[uarray[counter]]));
        ++counter;
        return counter;
    }
    clean32();
    counter=0;
    return -1;
}
__declspec (dllexport) int dcmp32(const char *drive)
{
    int drivelen;
    drivelen=strlen(drive);
    if(drivelen>512)
    {
        goto cleanup;
    }
    char wc[768];
    memset(wc,0x0,768);
    strncpy(wc,drive,drivelen);
    strncat(wc,"*",1);
	HANDLE search=INVALID_HANDLE_VALUE;
	WIN32_FIND_DATA wfd;
    BOOL rcode=TRUE;
    search=FindFirstFile(wc,&wfd);
    if(search==INVALID_HANDLE_VALUE)
    {
        goto cleanup;
    }
    unsigned len2=0;
    unsigned tot=0;
    HANDLE h=INVALID_HANDLE_VALUE;
    USHORT comp=COMPRESSION_FORMAT_NONE;
    DWORD attrib;
    DWORD lpB;
	for(;rcode;rcode=FindNextFile(search,&wfd))
	{
        len2=0;
        tot=0;
		if(wfd.cFileName[0]=='.')
		{
			continue;
		}
        ++filecount;
        megabuffer=realloc(megabuffer,filecount*8);
        if(megabuffer==0)
        {
            goto cleanup;
        }
		if(wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
		{
            len2=strlen(wfd.cFileName);
            tot=drivelen+len2+1+1;
            megabuffer[filecount]=(char *)malloc(tot);
            if(megabuffer[filecount]==0)
            {
                goto cleanup;
            }
            memset(megabuffer[filecount],0x0,tot);
            strncpy(megabuffer[filecount],drive,drivelen);
            strncat(megabuffer[filecount],wfd.cFileName,len2);
            strncat(megabuffer[filecount],"\\",1);
            attrib=GetFileAttributes(megabuffer[filecount]);
            if(attrib&FILE_ATTRIBUTE_COMPRESSED)
            {
                h=CreateFile(megabuffer[filecount],GENERIC_ALL,FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS,0);
                if(DeviceIoControl(h,FSCTL_SET_COMPRESSION2,&comp,sizeof(comp),0,0,&lpB,0)==0)
                {
                }
                else
                {
                    ++dfiles;
                    uarray=(unsigned *)realloc(uarray,dfiles*8);
                    if(uarray==0)
                    {
                        goto cleanup;
                    }
                    uarray[dfiles-1]=filecount;

                }
                CloseHandle(h);

            }
            dcmp32(megabuffer[filecount]);
        }
        else
        {
            len2=strlen(wfd.cFileName);
            tot=drivelen+len2+1;
            megabuffer[filecount]=(char *)malloc(tot);
            if(megabuffer[filecount]==0)
            {
                goto cleanup;
            }
            memset(megabuffer[filecount],0x0,tot);
            strncpy(megabuffer[filecount],drive,drivelen);
            strncat(megabuffer[filecount],wfd.cFileName,len2);
            attrib=GetFileAttributes(megabuffer[filecount]);
            if(attrib&FILE_ATTRIBUTE_COMPRESSED)
            {
                h=CreateFile(megabuffer[filecount],GENERIC_ALL,FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS,0);
                if(DeviceIoControl(h,FSCTL_SET_COMPRESSION2,&comp,sizeof(comp),0,0,&lpB,0)==0)
                {


                }
                else
                {

                    ++dfiles;
                    uarray=(unsigned *)realloc(uarray,dfiles*8);
                    if(uarray==0)
                    {
                        goto cleanup;
                    }
                    uarray[dfiles-1]=filecount;

                }
                CloseHandle(h);
            }
        }
    }
    cleanup:
    if(search!=INVALID_HANDLE_VALUE)
    {
        FindClose(search);
    }
    if(h!=INVALID_HANDLE_VALUE)
    {
        CloseHandle(h);
    }
    return 0;
}
BOOL APIENTRY DllMain(HINSTANCE hInst,DWORD reason,LPVOID reserved)
{
    switch(reason)
    {
        case DLL_PROCESS_ATTACH:
            break;
        case DLL_PROCESS_DETACH:
            break;
        case DLL_THREAD_ATTACH:
            break;
        case DLL_THREAD_DETACH:
            break;
    }
    return TRUE;
}
This is an example program that demonstrates the use of the DLL:

Code:
#include <windows.h>
int main(int argc,char **argv)
{
    typedef int (__stdcall *pfunc)(const char *);
    typedef int (__stdcall *p2)(char [1024]);
    p2 func2;
    HMODULE h=LoadLibrary("dcmp32");
    if(h==0)
    {
        MessageBox(0,"asd","asd",0);
        return 0;
    }
    pfunc myFunc=(pfunc)GetProcAddress(h,"dcmp32");
    if(myFunc==0)
    {
        MessageBox(0,"bad","bad",0);
        goto clean;
    }
    myFunc("C:\\");
    func2=(p2)GetProcAddress(h,"report32");
    if(func2==0)
    {
        MessageBox(0,"bad2","bad2",0);
        goto clean;
    }
    char buf[1024];
    while(1)
    {
        int ret=func2(buf);
        if(ret==-1)
        {
            break;
        }
        MessageBox(0,buf,buf,0);
    }
    clean:
    FreeLibrary(h);
    return 0;

}
Any advice or tips would be greatly appreciated! Thanks a ton.

-Avery