load bitmap from resource

D

dotnetchic

(Sorry about cross-post to MFC...got no reply so I'm reposting here)

Porting my code over from VC++6 to MC++, loading bitmaps from resources
broke. This code is in a lib file (previously, it was a dll)...don't
know how that affects it. Here's what we had previously that worked:

AFX_MANAGE_STATE(AfxGetStaticModuleState());
HINSTANCE hInst = GetModuleHandle("ThisLibrary.dll");
HBITMAP hBitmap = ::LoadBitmap(hInst, MAKEINTRESOURCE(ID));

(1) I tried to load the dll as above, which didn't work. (2) I tried
getting the module handle from ThisLibrary.lib (which is how it is
currently compiled), which did not work. (3) I tried compiling as
native and repeating 1 & 2 above, which did not work. (4) Also tried
load image which didn't work:
HBITMAP hBitmap = (HBITMAP)LoadImage(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDB_LOOPC01),
IMAGE_BITMAP,
0, 0, 0);

Can someone tell me how to resolve this? Is there a better way to load
resources at runtime?

TIA,
Sharon
 
J

Jeff Partch [MVP]

dotnetchic said:
(Sorry about cross-post to MFC...got no reply so I'm reposting here)

Porting my code over from VC++6 to MC++, loading bitmaps from resources
broke. This code is in a lib file (previously, it was a dll)...don't
know how that affects it. Here's what we had previously that worked:

At first blush I'd say your failure probably stems from the fact that static
libraries do not contain resources.
 
B

Ben Voigt

Jeff Partch said:
At first blush I'd say your failure probably stems from the fact that
static libraries do not contain resources.

Additionally, if you are porting to the Managed environment, realize that
the managed resource editor is totally incompatible with Win32 resources,
and there is a ResourceManager class in the BCL for dealing with managed
resources.

..resx, .resources => managed resources (.NET ResourceManager)
..rc, .res => Win32 resources (win32 api LoadResource, etc.)
 
D

dotnetchic

Jeff said:
At first blush I'd say your failure probably stems from the fact that static
libraries do not contain resources.

Then why would IS_INTRESOURCE return true for the resource?
 
D

dotnetchic

Ben said:
Additionally, if you are porting to the Managed environment, realize that
the managed resource editor is totally incompatible with Win32 resources,
and there is a ResourceManager class in the BCL for dealing with managed
resources.

Right. But all I'm trying to do is load a bitmap from a resource. So
to accomplish this, I should (1) recompile the library containing the
bitmaps as dynamic and (2) load the the bitmaps from a section within
the main app compiled as native? Would this work?

Thanks,
Sharon
 
J

Jeff Partch [MVP]

dotnetchic said:
Then why would IS_INTRESOURCE return true for the resource?

It only tests bits. It says nothing about whether the passed in value
identifies a valid resource.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top