Public Group

#### Archived

This topic is now archived and is closed to further replies.

# Noob needing some help please

This topic is 5362 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I always seem to get the funky errors... I''m trying to load an image using the GDI then create a compatable D3D surface to load the image onto, but when I try to create the surface I get: HEAP[DXBitmap.exe]: Invalid allocation size - a3d70a60 (exceeded 7ffdefff) **Could not create surface for bitmap (**this line is an self defined error message) I think the problem is in LoadImage().. LoadImage() doesn''t seem to be working for me.. here''s the code.. HRESULT r = 0; HANDLE hImage; BITMAP Bitmap; //create the the bitmap using the GDI to obtain bitmap info char Path[] = "ZEN PIC.BMP"; // Load the image from disk into memory hImage = LoadImage( NULL, Path, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); if(hImage = NULL) { //wrong path or file doesn''t exist probably SetError("Unable to load bitmap"); return E_FAIL; } //get info on object GetObject(hImage, sizeof(BITMAP), &Bitmap); //unload the object once info obtained DeleteObject(hImage); //code to output width and height in pixels to debug win char error[50]; itoa(Bitmap.bmHeight,error,10); SetError(error); itoa(Bitmap.bmWidth, error, 10); SetError(error); When I output the Bitmap height and width to the debug window I get: -858993460 -858993460 Which seems really wrong, and I assume is why the surface it tries to create is too big. The program works fine when I take the Bitmap code out, and Loadimage works fine in my other programs.. Any info or suggestions would be greatly appreciated! Thanks! Sean

##### Share on other sites

But it looks like you are creating hImage without setting it to NULL. So it has some random value.

You then try to load a bitmap to it, and check to see if it''s NULL. The bitmap may or may not have loaded correctly, but hImage was never NULL, so the code to check to see if it loaded correctly will always return that it did.

set hImage to NULL when you create it, and see if that helps. I bet you''ll see after you do that, that your Bitmap isn''t loading correctly.

Good luck!

~~~~~~~~~~~
Chris Vogel
~~~~~~~~~~~

##### Share on other sites
That helped, but it wasn''t HBITMAP.. Even if I set it to NULL and zero the memory I don''t get the error after creation, but what you said caused me to set the BITMAP structure to NULL and zero it first too, now when I output the Height and Width I get 0''s so it seems the problem has to do with:

GetObject(hBitmap, sizeof(BITMAP), &Bitmap);

It seems the Bitmap structure isn''t getting the info, of course I still have no idea why but it''s a start! heh thanks!

##### Share on other sites
OMG I''m laughing my ass off.. what a true noob mistake.. here it is..

if(hImage = NULL) {
//wrong path or file doesn''t exist probably
return E_FAIL;
}

Duh!
asjkfhqejf

Thanks for the help!

##### Share on other sites
heh, I missed that too.

if (hImage = NULL)...if (hImage == NULL)

Makes a big difference =)

[edited by - Radagar on November 13, 2003 2:58:30 PM]

##### Share on other sites
That''s why I write comparisons like this

if(NULL == hImage)

that way if you write

if(NULL = hImage)

You''ll get a compile error instead of a runtime error.

1. 1
Rutin
25
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 14
• 11
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
631754
• Total Posts
3002104
×