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


Menu Resources in DLLs

Recommended Posts

Mike    141
I have a menu resource in a DLL and I am trying to do the following:
	wc.cbClsExtra		= NULL;
	wc.cbWndExtra		= NULL;
	wc.hbrBackground	= (HBRUSH)::GetStockObject( GRAY_BRUSH );
	wc.hCursor			= ::LoadCursor( NULL, IDC_ARROW );
	wc.hIcon			= ::LoadIcon( NULL, IDI_APPLICATION );
	wc.hInstance		= hInstance;
	wc.lpfnWndProc		= WinProc;
	wc.lpszClassName	= APP_NAME;
This is just a small portion of your standed window setup code, the only difference being that it is called in a DLL. For some resion, MAKEINTRESOURCE gives me a bad pointer. Why is this? Is it because you cannot have menu resources in a DLL? the code works fine as long as its not in a DLL. Any Ideas?

Share this post

Link to post
Share on other sites
Box2020    142
I am not sure if thiis will help as it is MFC based

The MSDN gives the following example code

  BOOL CMyApp::InitInstance()
//Default Appwizard code.

hRes= LoadLibrary("ResourceD.dll");
//Rest of wizard code

return CWinApp::InitInstance();

I am not sure about the SDK equivelent.

One approach could be to set ws.lpszMenuName to NULL
and then dynamincaly load the menu with LoadMenu(hRes,IDR_MENI1)
where hRes is the handle to the loaded DLL

Hope this helps

Share this post

Link to post
Share on other sites
Darrell L    122
Although I''ve never tried it, I don''t think you can mix/match modules when registering a class. That''s because you only have one instance variable to specify for both your winproc as well as your resources. So, if your winproc is in hInstance I think your menu you specify via RegisterClass must also be in that module.

What you could do is set the menu handle to NULL for the class and then use LoadMenu and SetMenu to set up the main window menu during CreateWindow WM_NCCREATE processing. The resource dll will have had to have been pre-loaded (via LoadLibrary as Box2020 mentioned, or via static linking) and you would need that dll''s module handle for use as the hInstance parm in the LoadMenu call.

Hope this helps.

Share this post

Link to post
Share on other sites