|
|
谁能告诉为什么_lseek会出错,我用windows游戏编程大师技巧(第二版)总的加载BMP的代码,(是用VC2005编译)都会在_lseek自动跳出程序,停止运行。
代码如下:
int Load_Bitmap_File(BITMAP_FILE_PTR bitmap,char * filename)
{
int file_handle,index;
UCHAR *temp_buffer = NULL;
OFSTRUCT file_data;
if((file_handle = OpenFile(filename,&file_data,OF_READ))==-1)
{
return 0;
}
_lread(file_handle,&bitmap->bitmapfileheader,sizeof(BITMAPFILEHEADER));
if(bitmap->bitmapfileheader.bfType != BITMAP_ID)
{
_lclose(file_handle);
return 0;
}
_lread(file_handle,&bitmap->bitmapinfoheader,sizeof(BITMAPINFOHEADER));
if(bitmap->bitmapinfoheader.biBitCount = 8)
{
_lread(file_handle,&bitmap->palette,MAX_COLORS_PALETTE*sizeof(PALETTEENTRY));
for(index=0;index<MAX_COLORS_PALETTE;index++)
{
int temp_color = bitmap->palette[index].peRed;
bitmap->palette[index].peRed = bitmap->palette[index].peBlue;
bitmap->palette[index].peBlue = temp_color;
bitmap->palette[index].peFlags = PC_NOCOLLAPSE;
}
}
_lseek(file_handle,-(int)(bitmap->bitmapinfoheader.biSizeImage),SEEK_END);
if(bitmap->bitmapinfoheader.biBitCount ==8||
bitmap->bitmapinfoheader.biBitCount == 16||
bitmap->bitmapinfoheader.biBitCount == 24)
{
if(bitmap->buffer)
free(bitmap->buffer);
if(!(bitmap->buffer = (UCHAR *)malloc(bitmap->bitmapinfoheader.biSizeImage)))
{
_lclose(file_handle);
return 0;
}
_lread(file_handle,bitmap->buffer,bitmap->bitmapinfoheader.biSizeImage);
}else
{
return 0;
}
_lclose(file_handle);
Flip_Bitmap(bitmap->buffer,bitmap->bitmapinfoheader.biWidth*(bitmap->bitmapinfoheader.biBitCount/8),bitmap->bitmapinfoheader.biHeight);
return 1;
} |
|