(*info = (BITMAPINFO *)malloc(infosize)) == NULL)

I have seen this example in many places but this cast gibes me errors can anyone help?

Don’t you think it would help to at least say what kind of error it is?

my guess would be that info is not a double pointer. info is probably just a single pointer to a BITMAPINFO structure. i used the words “guess” and “probably” because you didn’t share any source code

jebus

Originally posted by Trying_To_LoadBitmap:
I have seen this example in many places but this cast gibes me errors can anyone help?

FILE * fp;
BITMAPFILEHEADER header;
BITMAPINFO ** info;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
GLubyte * BitmapBits[1]; /* Bitmap data */

int DrawGLScene(GLvoid) // Here’s Where We Do All The Drawing
{
int infosize,
bitsize;

fp = fopen("NeHe.bmp", "rb");
if (fp == NULL)
	return (NULL);
fread(&header, sizeof(BITMAPFILEHEADER), 1, fp);
if(header.bfType != 'MB') 
{
	fclose(fp);
	return(NULL);
}
infosize = header.bfOffBits - sizeof(BITMAPFILEHEADER);
*info = (BITMAPINFO *)malloc(infosize);
if ((*info = (BITMAPINFO *)malloc(infosize)) == NULL)
{
/* Couldn't allocate memory for bitmap info - return NULL... */
fclose(fp);
return (NULL);
}

fread(&info, 1, infosize, fp);
if ((bitsize = (*info)->bmiHeader.biSizeImage) == 0)
	bitsize = ((*info)->bmiHeader.biWidth * (*info)->bmiHeader.biBitCount + 7 / 8 * 
				abs((*info)->bmiHeader.biHeight));
glViewport(0,0,Width,Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,(GLfloat)Width, 0.0, (GLfloat)Height, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glRasterPos2i(0,0);
glDrawPixels((*info)->bmiHeader.biWidth, (*info)->bmiHeader.biHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, BitmapBits);
return TRUE;										// Keep Going

}

Sorry for the lack of info that is what my code looks like and the error is a casting error.

and the error is a casting error.

What is the exact error message? Error casting from what type to what type?

*info = (BITMAPINFO *)malloc(infosize);
if ((*info = (BITMAPINFO *)malloc(infosize)) == NULL)

Why allocate memory twice? You have a memory leak here. Does it give the cast error on one of these lines or both of them (I assume that’s the line you’re talking about)?

No those lines were repeated to see if it was the logical comparision causing the problem however I did figure out my problem.

this
BITMAPINFO ** info;
should have been
BITMAPINFO *info[1];
that.

I do still have problems but now I am past that part.

I’m confused as to why info even needs to be a pointer to a pointer. You were getting errors before because you were trying to store the pointer return by malloc into nonexistant memory via the uninitialised pointer to a pointer. You fixed it by simply changing it to an array of a single pointer, that which of course did at least make the pointer valid. I personally would just have made info a pointer to a BITMAPINFO and been done with it.

Ok I agree with you advice about it working as only a pointer. I combined the examples of two different examples and mix matched the wrong portions. One had multipule images. However I still get an error with the BitmapBits. It is failing on the glDrawPixels. Any suggestions?
FILE * fp;
BITMAPFILEHEADER header;
BITMAPINFO info;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
GLubyte * BitmapBits; /
Bitmap data */

int Width;
int Height;

int InitGL(GLvoid) // All Setup For OpenGL Goes Here
{
return TRUE; // Initialization Went OK
}

int DrawGLScene(GLvoid) // Here’s Where We Do All The Drawing
{
int infosize,
bitsize;

fp = fopen("NeHe.bmp", "rb");
if (fp == NULL)
	return (NULL);
fread(&header, sizeof(BITMAPFILEHEADER), 1, fp);
if(header.bfType != 'MB') 
{
	fclose(fp);
	return(NULL);
}
infosize = header.bfOffBits - sizeof(BITMAPFILEHEADER);
if ((info = (BITMAPINFO *)malloc(infosize)) == NULL)
{
/* Couldn't allocate memory for bitmap info - return NULL... */
fclose(fp);
return (NULL);
}

// fread(&info, 1, infosize, fp);
if (fread(info, 1, infosize, fp) < infosize)
{
/* Couldn’t read the bitmap header - return NULL… */
free(info);
fclose(fp);
return (NULL);
}

if ((bitsize = (info)-&gt;bmiHeader.biSizeImage) == 0)
	bitsize = ((info)-&gt;bmiHeader.biWidth * (info)-&gt;bmiHeader.biBitCount + 7 / 8 * 
				abs((info)-&gt;bmiHeader.biHeight));
if ((BitmapBits = (GLubyte *)malloc(bitsize)) == NULL)
    {
    /* Couldn't allocate memory - return NULL! */
    free(info);
    fclose(fp);
    return (NULL);
    }

if (fread(BitmapBits, 1, bitsize, fp) &lt; bitsize)
    {
    /* Couldn't read bitmap - free memory and return NULL! */
    free(info);
    free(BitmapBits);
    fclose(fp);
    return (NULL);
    }

/* OK, everything went fine - return the allocated bitmap... */
fclose(fp);

glViewport(0,0,Width,Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,(GLfloat)Width, 0.0, (GLfloat)Height, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glRasterPos2i(0,0);
glDrawPixels((info)-&gt;bmiHeader.biWidth, (info)-&gt;bmiHeader.biHeight, GL_BGRA_EXT, GL_UNSIGNED_BYTE, BitmapBits);
return TRUE;										// Keep Going

}

However I still get an error with the BitmapBits. It is failing on the glDrawPixels. Any suggestions?

Come on, don’t you realize you have to at least say what i wrong, instead of just saying something is wrong? What happens? Does it compile, does it give you an error message while compiling, does it draw an image but the colors are wrong, or is the image distorted, do you get an access violation? We can’t help unless you say what’s wrong.