Archived

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

Chocoboko

Using resource(RC) files in DLLs

Recommended Posts

Hi, I am making a DLL to open a window and use a resource file to make a popup menu. But for some reason, the DLL is using the resource file of the host application and not the DLL itself. When I tried to open a menu, I got the menu of the host application window instead of the menu of the DLL window. Does any of you know what might cause this? Thank you.

Share this post


Link to post
Share on other sites
You must be using the handle of your application instead of the DLL.

Load the DLL using LoadLibrary and use the returned handle with LoadMenu

That should work

Share this post


Link to post
Share on other sites
What hInstance are you using for the Load*() calls? You should use the hInstance passed to DllMain().

However, creating windows in a DLL can be tricky, according to MSDN. Here''s an excerpt from: Miscellaneous DLL Topics:

quote:

A dynamic library can load resources (such as icons, strings, and bitmaps) either from the library file or from the file of the program that calls the library. The functions that load resources require an instance handle. If the library uses its own instance handle (which is passed to the library during initialization), the library can obtain resources from its own file. To load resources from the calling program''s .EXE file, the library function requires the instance handle of the program calling the function.

Registering window classes and creating windows in a library can be a little tricky. Both the window class structure and the CreateWindow call require an instance handle. Although you can use the library module''s instance handle in creating the window class and the window, the window messages still go through the message queue of the program calling the library when the library creates the window. If you must create window classes and windows within a library, it''s probably best to use the calling program''s instance handle.

Because messages for modal dialog boxes are retrieved outside a program''s message loop, you can create a modal dialog box in a library by calling DialogBox. The instance handle can be that of the library, and the hwndParent argument to DialogBox can be set to NULL.



Share this post


Link to post
Share on other sites
This is really weird, but I am using the HINSTANCE passed from DllMain. Yet for some reason, it still wants to use the resource from the host application. Here is what I am doing:

1. I have a global HINSTANCE variable called "lib". In DllMain, I set lib to the HINSTANCE passed.

2. Load the library and use it to call a function called "InitPlugin" in the DLL. It passes the handle to the window through that function.

3. InitPlugin calls a function inside the DLL to create the window.

Anyway, loading the resouce through the lpszClassName variable in the Windows class structure doesn''t work. So I tried using "LoadMenu(lib,E_MENU)" to load it. It still loads the resource from the host application and not the DLL. Please help me if you can. Thank you very much.

Share this post


Link to post
Share on other sites