[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  Programming
. -> [Folder]  General
. . -> [Subject]  Win32 API Troubles
Home  |  Users  |  Search  |  FAQ
Register forum user name
Forgotten password?

Win32 API Troubles

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

Posted by Nick Cash   USA  (626 posts)  [Biography] bio
Date Tue 15 Feb 2005 12:04 AM (UTC)
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 );
    sprintf( buf, "IDB_IMAGE1 = %d", IDB_IMAGE1 );
  /* bmp = LoadImage(hInstance,
   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 );
    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
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #1 on Tue 15 Feb 2005 12:19 AM (UTC)
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

[Go to top] top

Posted by Nick Cash   USA  (626 posts)  [Biography] 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

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
[Go to top] top

Posted by Nick Cash   USA  (626 posts)  [Biography] bio
Date Reply #3 on Wed 16 Feb 2005 04:39 AM (UTC)
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
[Go to top] 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.


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

Go to topic:           Search the forum

[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]