🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Easy question - loading DLL's resources

Started by
2 comments, last by Korndog 24 years, 5 months ago
Hi, I have an exe and a dll. I made the dll by using VC++, going to New/MFC Appwizard, and then added a resource file with only the line: ------------------ MYBITMAP BITMAP "bitmap1.bmp" ------------------ I compiled it, and then put it in my directory with the exe. In the exe code, I tried to load it with this code: ------------------ HMODULE hResourceDLL = LoadLibraryEx("temp2a.dll", NULL, LOAD_LIBRARY_AS_DATAFILE); hbm = (HBITMAP) LoadImage(hResourceDLL, szBitmap, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION); FreeLibrary(hResourceDLL); ------------------ szBitmap is the resource name string (in this case, "MYBITMAP" and hbm is a HBITMAP. It doesn''t work. But I have a picture file in the EXE, and when I load it like this, ------------------ hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), szBitmap, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION); ------------------ it works! So is it that the dll I made is wrong, or is this code wrong, or...? Any help with this puzzling problem would be much appreciated. - Puzzled in Texas
Advertisement
There are a couple of ways to do what your after and with that comes a couple of different problems with each.

The best method would be to use AfxFindResoureceHandle() and AfxLoadString().

Although these two functions make resource finding easier because it proplerly traverses all registered AFX modules (you did say you used the wizard to make it) be aware that you CANNOT have any name collisions in your modules because it will always stop upon finding the first reference and thus displaying the wrong resource if you have more than two.

But as with any programming problem, there is always more than one way to flip a bit, so, maybe someone else has a different approach.

~deadlinegrunt

Thank you for replying, but I re-created the DLL into a Win 32 DLL instead of using AppWizard. I have narrowed the problem down to two things:

1) LoadLibraryEx returns a negative number. I think this is a bad thing

2) If I use LoadLibrary instead, it returns a positive number but then the width and height of the bitmap are insanely low negative numbers (like -1000000000)

I am not sure what this means...
Whoa! I figured it out.
I replaced LoadLibraryEx with LoadLibrary
Strange....
A little while ago my friend found out that I couldn''t use LoadImage with LOAD_LIBRARY_AS_DATAFILE in the LoadLibraryEx, so I replaced LoadImage with LoadResource.
Of course, that didn''t work
So after many a trial and error, I stuck LoadLibrary in and it worked perfectly.

If LOAD_LIBRARY_AS_DATAFILE has ever worked for whomever is reading this, let me know : )

This topic is closed to new replies.

Advertisement