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.
}