I am having troubles, like always. For a few semester projects in school I decided to make a graphical game using the Win32 API. Things have progressed rather smoothly, but I've hit a big snag. Apparently I cannot load from a resource. Whats funny is I load my icons from the resource and that works just fine. Here is the function giving me trouble:
BMP *bitmap_from_resource(HINSTANCE hInstance, WORD resource)
{
BMP *bitmap = NULL;
HBITMAP bmp;
CREATE( bitmap, BMP, 1 );
{
char buf[100];
sprintf( buf, "Bitmap_from_resource: Beginning resource is %d", resource );
write_log(buf);
sprintf( buf, "IDB_IMAGE1 = %d", IDB_IMAGE1 );
write_log(buf);
}
/* bmp = LoadImage(hInstance,
MAKEINTRESOURCE(resource),
IMAGE_BITMAP,
0,
0,
LR_DEFAULTCOLOR);*/
bmp = LoadBitmap(hInstance, MAKEINTRESOURCE(resource));
bitmap->bitmap = bmp;
bitmap->width = 640;
bitmap->height = 480;
if ( bmp == NULL )
{
long error = GetLastError();
char string[100];
sprintf(string, "Bitmap_from_resource: NULL bmp. Error %ld Res: %ld", error, resource );
write_log( string );
FreeBitmap( bitmap );
return NULL;
}
/*everything ok, return */
return bitmap;
}
The commented out LoadImage call was an alternate way of trying to do this, but neither works. As to why, I dont know, my log of this spews (btw, IDB_IMAGE1 is defined as 2000):
1. Bitmap_from_resource: Beginning resource is 2357
2. IDB_IMAGE1 = 2000
3. Bitmap_from_resource: NULL bmp. Error 1812 Res: 2357
4. Loading of Image1 failed!
5. Last error: 183
Yet the way I call it is this:
if ( (Slide = (BMP *)bitmap_from_resource( game->hInstance, dc, IDB_IMAGE1 ) ) == NULL )
{
char buf[128];
long error = GetLastError();
write_log( "Loading of Slide1 failed!" );
sprintf( buf, "Last error: %ld", error );
write_log( buf );
}
else
write_log( "Slide1 loaded successfully" );
So I have no idea as to why when I call the function with IDB_IMAGE1 it turns up 2357 when it is defined as 2000. The result is a resource error that will not go away.
Any ideas? See anything wrong with these functions? I'm not Win32 API expert since this is more or less my first -REAL- adventure through the Win32 API realm.
Thanks for anything and everything in advance, this is for school so I appreciate it doubly :P |