Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ Programming ➜ General ➜ Win32 API Troubles

Win32 API Troubles

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Nick Cash   USA  (626 posts)  Bio
Date Tue 15 Feb 2005 12:04 AM (UTC)
Message
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

~Nick Cash
http://www.nick-cash.com
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #1 on Tue 15 Feb 2005 12:19 AM (UTC)
Message
Sorry but I have no idea. I've never loaded bitmaps using resources, and since bitmap is a generally messy format I tend to do all my loading via TGA. And to make matters worse, I try to steer clear of the Win32 API and use OpenGL instead. (Haven't used DirectX in a while but that's ok too.) Good luck figuring out this beast...

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Nick Cash   USA  (626 posts)  Bio
Date Reply #2 on Tue 15 Feb 2005 01:46 AM (UTC)

Amended on Tue 15 Feb 2005 01:47 AM (UTC) by Nick Cash

Message
Yeah, thanks :P I've been meaning to jump into my OpenGL book for sometime now, but I figure that can be my project next year (some type of 3D thing). I decided to go for simplicity, but I guess its not too simple anymore. I wish this were as easy to do as my MUD :P. It just seems like it should work...

The strangest part is that after I call it resource is 2357 instead of 2000 like it should be....

~Nick Cash
http://www.nick-cash.com
Top

Posted by Nick Cash   USA  (626 posts)  Bio
Date Reply #3 on Wed 16 Feb 2005 04:39 AM (UTC)
Message
Just for anyone who was curious...

Well, this was a strange problem. My friend EvilPuffBall figured out a way around it. Apparently if you call LoadBitmap or LoadImage in the function that contains all of the basic windoze crap (registering of the class, creating the window, etc..) it would work. So, I am able to use my resources but at the expense of a more dynamic system and cleaner code. Pfft, some trade off.

I hate you windows :P

~Nick Cash
http://www.nick-cash.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


13,506 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.