[comp.windows.ms.programmer] LoadBitmap help resummarization of help needed

jdb@reef.cis.ufl.edu (Brian K. W. Hook) (03/19/91)

Alright, I looked over my code a bit more and did a lot more thorough
tracing, and this is what I have found out:

1.  The program dies IN CreateWindow(), but not until it passes the message
WM_CREATE to MainWndProc.  When I used TDW and did an F7 or F8 at
CreateWindow(), I would get an Exception 13, code -4.  However, if I did an
F4 (trace up to) at switch WM_CREATE:, it would run just fine to that
point, but immediately exception out at:

hBitMap=LoadBitmap(hInst,"boom");

2.  For some reason, substituting in a standard Windows bitmap and using:

hBitMap=LoadBitmap(NULL,"OLD_BITMAP");  // OLD_BITMAP for demonstrative
					// purposes

Still gets the error when I thought that it would get rid of the error.
Hmm...

3.  When I comment out LoadBitmap() from WM_CREATE, the program works fine.

Anyway, I can't seem to find the problem still.  My RC file has the
following as the last line:

boom BITMAP BOOM.BMP

4.  BOOM.BMP *IS* in the current directory.  RC works just fine.

5.  As before, I am using a VGA, 386-33, Win 3.00, Borland C++ 2.00, Small
memory model, Windows .EXE, TDW for debugging, 8MB of RAM, debug info on,
optimizations off.

6.  Could I be running out of memory locally or something?  The
documentation on LoadBitmap is REAL lame.  Where does it takes its memory
from?  The global heap?  Local heap?  Stack?  How do I change these in the
IDE?

Help would be appreciated,

Brian

curt@cctb.wa.com (Curt Johnson) (03/22/91)

In article <27518@uflorida.cis.ufl.EDU> jdb@reef.cis.ufl.edu (Brian K. W. Hook) writes:
Program dies during:
| hBitMap=LoadBitmap(hInst,"boom");


| 2.  For some reason, substituting in a standard Windows bitmap and using:
| 
| hBitMap=LoadBitmap(NULL,"OLD_BITMAP");  // OLD_BITMAP for demonstrative
| 					// purposes
Shouldn't that be:
	hBitMap=LoadBitmap(NULL,IDI_APPLICATION); //no quotes for standard Windows bitmaps

| Anyway, I can't seem to find the problem still.  My RC file has the
| following as the last line:
| 
| boom BITMAP BOOM.BMP

I have two guesses:

1. If boom is #defined as anything you will have a problem.

2. If the last line in your .RC file is not followed by a linefeed it is possible
   that is is being ignored (if RC.EXE is not written well).


Curt Johnson == curt@cctb.wa.com

jdb@reef.cis.ufl.edu (Brian K. W. Hook) (03/22/91)

In article <bjs4g8ti2@cctb.wa.com> curt@cctb.wa.com (Curt Johnson) writes:
|>In article <27518@uflorida.cis.ufl.EDU> jdb@reef.cis.ufl.edu (Brian K. W. Hook) writes:
|>Program dies during:
|>| hBitMap=LoadBitmap(hInst,"boom");
|>
|>
|>| 2.  For some reason, substituting in a standard Windows bitmap and using:
|>| 
|>| hBitMap=LoadBitmap(NULL,"OLD_BITMAP");  // OLD_BITMAP for demonstrative
|>| 					// purposes
|>Shouldn't that be:
|>	hBitMap=LoadBitmap(NULL,IDI_APPLICATION); //no quotes for standard Windows bitmaps

Actually, you're right....but I changed it to without quotes a while ago
and got it flagged as being an unknown identifier....and yes, I have
inclued WINDOWS.H...:-)

|>
|>| Anyway, I can't seem to find the problem still.  My RC file has the
|>| following as the last line:
|>| 
|>| boom BITMAP BOOM.BMP
|>
|>I have two guesses:
|>
|>1. If boom is #defined as anything you will have a problem.

Tried changing the name to things like ZZZZ and doing and #ifdef
#undef....still same error.

|>
|>2. If the last line in your .RC file is not followed by a linefeed it is possible
|>   that is is being ignored (if RC.EXE is not written well).

Moved it to ther beginning.  Same thing.

poffen@sj.ate.slb.com (Russ Poffenberger) (03/28/91)

In article <27570@uflorida.cis.ufl.EDU> jdb@reef.cis.ufl.edu (Brian K. W. Hook) writes:
>In article <bjs4g8ti2@cctb.wa.com> curt@cctb.wa.com (Curt Johnson) writes:
>|>In article <27518@uflorida.cis.ufl.EDU> jdb@reef.cis.ufl.edu (Brian K. W. Hook) writes:
>|>Program dies during:
>|>| hBitMap=LoadBitmap(hInst,"boom");
>|>
>|>
>|>| 2.  For some reason, substituting in a standard Windows bitmap and using:
>|>| 
>|>| hBitMap=LoadBitmap(NULL,"OLD_BITMAP");  // OLD_BITMAP for demonstrative
>|>| 					// purposes
>|>Shouldn't that be:
>|>	hBitMap=LoadBitmap(NULL,IDI_APPLICATION); //no quotes for standard Windows bitmaps
>
>Actually, you're right....but I changed it to without quotes a while ago
>and got it flagged as being an unknown identifier....and yes, I have
>inclued WINDOWS.H...:-)
>
[stuff deleted]

Here is a fragment of my code that works. If yours is similar, can't
understand why it doesn't work. Possibly you have corrupted resources or
memory like deleting stock objects, or not deleting objects when done, or
some such. Windows is quite picky about these things..

    HBITMAP sbitmap,oldbitmap;
    HDC hMemoryDC;
    hMemoryDC = CreateCompatibleDC(hdc);
    sbitmap = LoadBitmap(hinst,"saver");
    oldbitmap = SelectObject(hMemoryDC,sbitmap);
    BitBlt(hdc,border_x + 3 + SQ_SIZE_X * logo_x,
           border_y + 3 + SQ_SIZE_Y * logo_y,
           32,32,hMemoryDC,0,0,SRCCOPY);
    SelectObject(hMemoryDC,oldbitmap);
    DeleteObject(sbitmap);
    DeleteDC(hMemoryDC);


Notice how old objects are saved, restored, and unused objects are then
deleted. This is VERY important.

Russ Poffenberger               DOMAIN: poffen@sj.ate.slb.com
Schlumberger Technologies       UUCP:   {uunet,decwrl,amdahl}!sjsca4!poffen
1601 Technology Drive		CIS:	72401,276
San Jose, Ca. 95110             (408)437-5254