Hi,

I want to load a resource (bmp-picture) from a dll via FindResource() / LoadResource / LockResource / SizeOfResource / ...
But I cannot load a resource in resourcetyp "BITMAP".
How can I use resources with resourcetyp "BITMAP" ?

Greetings,
Nordwind64
Posted on 2002-07-26 06:44:25 by Nordwind64
can you explain your problem further?

if you want a bitmap handle use LoadBitmap instead
if you use LoadResource you get the full bitmapfile, with a bitmapfileheader.
Posted on 2002-07-26 07:29:00 by beaster
Hi,

I use Ernie's lib to load jpg, gif and bmp resources.
But I cannot load a resource with resourcetype "BITMAP", only with resourcetype "IMAGE".
But I need it in "BITMAP"...

Greetings,
Nordwind64
Posted on 2002-07-26 07:39:27 by Nordwind64
i don't see a problem defining a bitmap as IMAGE in a resource file, but this is the only possibility to solve your problem:

you have to rewrite or change the "BitmapFromResource.asm" file and compile the whole lib again.
this is how it looks like:



.data

szImage BYTE "IMAGE", 0

.code
;-------------------------------------------------------------------------------
BitmapFromResource PROC hModule: dword, ResNumber:DWORD
LOCAL hResource:DWORD, dwFileSize:DWORD, hImage:DWORD

; get a resource handle (address) and resource length from the executable
invoke FindResource, NULL, ResNumber, ADDR szImage
mov hResource, eax
invoke LoadResource, NULL, eax
invoke LockResource, eax
mov hImage, eax
invoke SizeofResource, NULL, hResource
mov dwFileSize, eax
.IF dwFileSize ; we use the resource size to determine if we got a
; legit image file to open
invoke BitmapFromMemory, hImage, dwFileSize
.ELSE
invoke SetLastError, ERROR_FILE_NOT_FOUND
mov eax, NULL
.ENDIF

; everything's been done for us now, just return
ret ; we're all done

BitmapFromResource ENDP
;-------------------------------------------------------------------------------
end


as you can see, BitmapFromResource just loads IMAGE resources. i think it should work if you change IMAGE to BITMAP, just try..
Posted on 2002-07-26 08:41:07 by NOP-erator
For bitmap and icon resources, you can use LoadBitmap, LoadIcon and LoadImage.
Posted on 2002-07-26 12:25:01 by comrade
Dang, I would concider that a bug, especially since I clearly remember coding this proc to accept either "IMAGE" or "BITMAP" for bitmap resources.

I must be getting old.

The "FindResource" invokation is the key here. Just change the string reference to "BITMAP" or just use the RT_BOTMAP constant, and all should be cool.

For extra credit, re-write the routine to accept *either* and submit to hutch for the next update.

(I'm not only old, I'm lazy!)
Posted on 2002-07-27 22:49:34 by Ernie
Ernie i suppose u mean RT_BITMAP and not RT_BOTMAP :grin:
Posted on 2002-07-28 03:12:25 by Allanon
Thank you!

But I changed "IMAGE" to "BITMAP" and put a Bmp, a Gif and a Jpg in a Dll and tried to load them, but it won't work.
Other resourcetypes had worked well, I had tested "PICTURES", "BMPS", e.g.
But Only "BITMAP" will not work.
Can you please post a working example ?

Thanks,
Nordwind64
Posted on 2002-07-29 07:50:47 by Nordwind64
i don't think that you can load a gif or jpeg with the resource type "BITMAP"..
just try to put them all as "IMAGE" in the resource file, this will work (hopefully)
Posted on 2002-07-29 13:33:50 by NOP-erator
Hi,

ok, but I use Ernies lib, it should also be possible with jpg and gif.
And what about a working example with bmp in "BITMAP" using Ernies source ?
Ernie ?

Greetings,
Nordwind64
Posted on 2002-07-29 22:38:48 by Nordwind64
OK, listen: if you include a gif or a jpeg you obviously HAVE to include it as "IMAGE"! But: if you want to include a real bitmap, both should work, "IMAGE" and "BITMAP". the solution is: include all your images as "IMAGE" (doesn't matter which type of images, bmp, jpeg, gif..etc) and load them with ernie's lib. that's it.. :confused:
Posted on 2002-07-30 03:27:19 by NOP-erator
Hi,

NOP-erator:
Ich schreib' dir mal deutsch, englisch ist nicht so mein Ding...
Ok, sagen wir mal, es gibt Gr?nde, aus denen ich unbedingt (hin und wieder) ein BMP Bild als Resourcetype "BITMAP" laden mu?. Nur gelingt mir das absolut nicht mit Ernies Quellcodes, auch nachdem ich im Code IMAGE in BITMAP umgewandelt hab'.
Wenn du es geschafft hast, dann poste doch mal bitte, wie's geht. S?tze wie es "sollte funktionieren" n?tzen mir jetzt im Moment nichts mehr, hab' schon ziemlich alles ausprobiert...

Gru?,
Nordwind64
Posted on 2002-07-30 08:39:30 by Nordwind64

Ich schreib' dir mal deutsch, englisch ist nicht so mein Ding...
Ok, sagen wir mal, es gibt Gr?nde, aus denen ich unbedingt (hin und wieder) ein BMP Bild als Resourcetype "BITMAP" laden mu?. Nur gelingt mir das absolut nicht mit Ernies Quellcodes, auch nachdem ich im Code IMAGE in BITMAP umgewandelt hab'.
Wenn du es geschafft hast, dann poste doch mal bitte, wie's geht. S?tze wie es "sollte funktionieren" n?tzen mir jetzt im Moment nichts mehr, hab' schon ziemlich alles ausprobiert...


little free translation:
I'll write in german, i don't like speaking english...
OK, let's say there are reasons, which force me to load a bitmap with "BITMAP" as the resource type. but this fails with ernie's lib, although i changed "IMAGE" to "BITMAP" in ernie's source.
if you managed to do it, please post how it works. i have no need for sentences like "it should work" , i tried nearly everything...

ok, nordwind, i took some time to try everything out for you, this are the results:
you can choose any resource type for your bitmap (for example "DATA", "IMAGE", "BLABLA") and it will work. but obviously you mustn't use "reserved" resource types like "BITMAP". this isn't a problem with ernie's lib, it's a problem with windows. even the sdk says:

An application can use FindResource to find any type of resource, but this function should be used only if the application must access the binary resource data when making subsequent calls to LockResource.

To use a resource immediately, an application should use one of the following resource-specific functions to find and load the resources in one call. (LoadBitmap)

For example, an application can use the LoadIcon function to load an icon for display on the screen. However, the application should use FindResource and LoadResource if it is loading the icon to copy its data to another application.


Fazit: if you really need to load bitmap resources with "BITMAP" as resource type, why the hell don't you use "LoadBitmap"??????? where's the difference???

sorry for "the hell", but i'm really confused about that and don't understand where actually the problem is.

btw: using RT_BITMAP as the last parameter of FindResource doesn't work either.

the only explanation i have is: if you compile as bitmap in a resource file with the type "BITMAP", the resource compiler somehow changes the actual bitmap into some easy-to-load-format or something, that can only be accessed by LoadBitmap to display it on the screen but can be loaded by FindResource, LoadResource, etc. to copy it to a file! i know, this explanation probably isn't right.. but I've no idea..

hope that helps, cya
Posted on 2002-07-30 12:43:09 by NOP-erator
Hi.

first, much thanks to you, NOP-erator!

little free translation:
I'll write in german, i don't like speaking english...

A very free translation...
I said: I'll write german, I'm not very good in speaking english.
I like speaking english, but I will make many errors...

Fazit: if you really need to load bitmap resources with "BITMAP" as resource type, why the hell don't you use "LoadBitmap"??????? where's the difference???

Ok, I made a Dll function (in my Dll) based on Ernie's lib, and I cannot be sure, wich gfx-format the user of my Dll is trying to load. And the users (I know) will first try to put their graphics in a Dll with Type "BITMAP", ok ?

LoadBitmap works ok, but cannot handle jpgs and gifs.

Hope you have understand me now.

Greetings,
Nordwind64
Posted on 2002-07-30 13:56:32 by Nordwind64
ok, i got your point, but i can't help you, i'm very sorry..

NOP
Posted on 2002-07-30 14:01:34 by NOP-erator
<insert very derogatory bad words about the Win32API here>


OK, so LoadResource does NOT work as advertised. Apparently, on the pre-defined resource types some undocumented (as far as I read MSDN) manipulations must be done, as I just cannot seem to get a handle on bitmap data stored as type "BITMAP" in a resource file.

Yet everything in MSDN says this is possible. Oh well....

Here is a work-around:



BitmapFromResource PROC hModule: dword, ResNumber:DWORD
LOCAL hResource:DWORD, dwFileSize:DWORD, hImage:DWORD

; get a resource handle (address) and resource length from the executable
invoke FindResource, hModule, ResNumber, ADDR szImage
.IF !eax
invoke LoadBitmap, hModule, ResNumber
.IF eax
ret ; gee, that was almost too eazy
.ENDIF
.ENDIF
mov hResource, eax
invoke LoadResource, hModule, eax
invoke LockResource, eax
mov hImage, eax
invoke SizeofResource, hModule, hResource
mov dwFileSize, eax
.IF dwFileSize ; we use the resource size to determine if we got a
; legit image file to open
invoke BitmapFromMemory, hImage, dwFileSize
.ELSE
invoke SetLastError, ERROR_FILE_NOT_FOUND
mov eax, NULL
.ENDIF

; everything's been done for us now, just return
ret ; we're all done

BitmapFromResource ENDP
Posted on 2002-07-30 17:48:28 by Ernie
Hi,

thank you !
I will try your code...

Your lib is really very good !!!

Greetings,
Nordwind64
Posted on 2002-07-30 22:45:17 by Nordwind64
Hi.


...
invoke FindResource,[ebp+8],[ebp+12],ADDR szImage
cmp eax,0
jne okto1

invoke LoadBitmap,[ebp+8],[ebp+12]
cmp eax,0
je pxhkerror
mov iBitmap, eax
jmp okto2
okto1:

mov hResource, eax
invoke LoadResource, [ebp+8], eax
invoke LockResource, eax
mov hImage, eax
invoke SizeofResource, [ebp+8], hResource
mov dwFileSize, eax
.IF dwFileSize ; we use the resource size to determine if we got a
; legit image file to open
invoke BitmapFromMemory, hImage, dwFileSize
mov iBitmap, eax
.ELSE
invoke SetLastError, ERROR_FILE_NOT_FOUND
mov eax, NULL
jmp bnde
.ENDIF

okto2:
invoke CreateCompatibleDC,0
...


Thank you, Ernie.
I made some little changes, now it works !!!

Thank you to all !

Nordwind64
Posted on 2002-07-31 10:43:50 by Nordwind64