Page 1 of 1

gflLoadBitmapFromHandle memory access fault

Posted: Wed Sep 27, 2006 4:57 pm
by Alucard
Hi,

I tryed to code a wrapper to read the images using gflLoadBitmapFromHandle.
My functions are

Code: Select all

static inline HANDLE openWrapper(char *filename)
{
FILE *pF=fopen(filename,"rb");
 if(pF!=NULL)
  setvbuf(pF, NULL, _IOFBF, 0xffff);
 return (HANDLE)pF;
}
static inline void closeWrapper(void *handle){
 fclose((FILE *)handle);
}
static DWORD GFLAPI readWrapper(void *handle, void *buffer, DWORD size){
 return fread(buffer,size,1,(FILE *)handle)==1 ? size : 0;
}
static DWORD GFLAPI writeWrapper(void *handle, void *buffer, DWORD size){
 return fwrite(buffer,size,1,(FILE *)handle)==1 ? size : 0;
}
static DWORD GFLAPI tellWrapper(void *handle){
 return ftell((FILE *)handle);
}
static DWORD GFLAPI seekWrapper(void *handle, long position, long origin){
 return fseek((FILE *)handle, position, origin)==0 ? position : -1;
}
The problem is when I try to load an image using a code like the following

Code: Select all

GFL_FILE_INFORMATION info;
GFL_LOAD_PARAMS load_params;
GFL_BITMAP *Bmp=NULL;

 gflGetDefaultLoadParams(&load_params);
 load_params.Callbacks.Read=readWrapper;
 load_params.Callbacks.Seek=seekWrapper;
 load_params.Callbacks.Tell=tellWrapper;
 load_params.Flags=GFL_LOAD_IGNORE_READ_ERROR;
 load_params.ColorModel=GFL_BGRA;
 load_params.Origin=GFL_BOTTOM_LEFT;
 load_params.LinePadding=4;
 load_params.FormatIndex=-1;
 load_params.ImageWanted=0;

GFL_HANDLE hFile=openWrapper(filename);
  gflLoadBitmapFromHandle(hFile, &Bmp, &load_params, &info);
the last function generates a memory access error at address 0 (NULL)

Any clues?

Re: gflLoadBitmapFromHandle memory access fault

Posted: Fri Oct 06, 2006 9:40 am
by xnview
Could you try

Code: Select all

static DWORD GFLAPI tellWrapper(void *handle){
 return ftell((FILE *)handle);
}
static DWORD GFLAPI seekWrapper(void *handle, long position, long origin){
 return fseek((FILE *)handle, position, origin);
}