Thread: sizeof() no good with array pointers? Or am I screwing this up?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    161

    sizeof() no good with array pointers? Or am I screwing this up?

    Ok, I'm sending this function a pointer to an unsigned char array and I want to find the length of it within the function so I can loop and process it or write with fwrite(), etc. Funny, I can malloc the array in a function I passed the pointer to, but I can find how much was malloc'd later.

    Code:
    unsigned char *ELFData;
    
    BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
    //obviously there's a ton of message handling being done here. This is how I'm calling the functions from here though
    
    LoadFile(&ELFData, &hData, eFileName, ELFheader, 0);
    
    SaveFile(&ELFData, &hData, eFileName, ELFheader, 0);
    }
    
    int LoadFile(u8 **buffer, u8 **headerdata, char* filename, int headerlen, u8 endian){
        FILE *f;
        int i, filesize;
    	f = fopen(filename,"rb");
    	fseek(f,0,SEEK_END);
    	filesize = ftell(f);
            if (*buffer) { free(*buffer); *buffer = 0; }
    	if (!(*buffer = (unsigned char*)malloc(filesize))) { 
    	    MessageBox(NULL,"Unable to allocate buffer memory (loadfile,2).","Error",0);
            fclose(f); return 0;
    	}
            //etc
    }
    
    int SaveFile(u8 **buffer, u8 **headerdata, char* filename, int headerlen, u8 endian){
        FILE *f;
        int i;
        int filesize = sizeof(*buffer); //if there was 3 meg allocated to it by an earlier call to LoadFile, it still says '4' or whatever.
    }
    Last edited by Viper187; 06-06-2008 at 10:04 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need some good information on Array, strings, and pointers
    By Sshakey6791 in forum C++ Programming
    Replies: 4
    Last Post: 11-30-2008, 03:16 AM
  2. Replies: 1
    Last Post: 10-21-2007, 07:44 AM
  3. Array of Pointers to Arrays
    By Biozero in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 02:31 PM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  5. Need help on pointer to VOID
    By dv007 in forum C Programming
    Replies: 19
    Last Post: 07-09-2002, 06:15 PM