loading bitmaps from resources in VC++

I’m trying to load my textures from bitmaps I put in my resources and I’m having trouble. I’m trying the following:

CBitmap Bitmap;
LPVOID lpBitmap;
BITMAP bm;
DWORD dwBitmapSize;

Bitmap.LoadBitmap(IDB_SKY);
Bitmap.SetBitmapDimension(128,128);
Bitmap.GetObject(sizeof(bm), &bm);
dwBitmapSize=bm.bmHeight*bm.bmWidthBytes * bm.bmPlanes;
Bitmap.GetBitmapBits(dwBitmapSize, lpBitmap);

glGenTextures(1, &m_textures[0]);

glBindTexture(GL_TEXTURE_2D, m_textures[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 128, 128, 0, GL_RGB, GL_UNSIGNED_BYTE, lpBitmap);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 128, 128, GL_RGB, GL_UNSIGNED_BYTE, lpBitmap);

Any tips on what I’m doing wrong?

What’s the problem exactly? Do you use 24bit BGR bitmap resources?

I’m assuming the bitmap resource’s original size is 128 by 128 correct?

Originally posted by DFrey:
I’m assuming the bitmap resource’s original size is 128 by 128 correct?

Yes the bitmap is 128x128. Actually I removed that function call since it seems unnecessary.

The problem is that I get an “Unhandled Exception 0xC0000005: Access Violation” on

glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, lpBitmap);

The call stack shows:
NVOGLNT! DrvSetPixelFormat + 468892 bytes