Click to See Complete Forum and Search --> : Resources in a DLL


Jim Bassett
May 27th, 1999, 01:22 PM
How does one compile the resources used by an MFC exe or MFC DLL so that they are in a DLL? Then how do you load those resources into the exe or DLL?


Thanks

Jim Bassett

Michael Decker
May 27th, 1999, 03:12 PM
The online MSDN help contains an article called "Create a Resource-Only DLL".

Oliver Kinne
May 28th, 1999, 02:53 AM
Just add the resources to the project which is the DLL and then compile the DLL as normal.

Every time you want to load a resource, do the following:

// save current resource handle
HINSTANCE hInstance = AfxGetResourceHandle();
// set resource handle to ourselves (the DLL)
AfxSetResourceHandle(theApp.m_hInstance);

// then display a dialog or...
int rv = dlg->DoModal();

// ...load an image list, or whatever
CImageList ilMyImageList.Create(IDB_IMAGE_LIST_ID, 16, 0, RGB(192, 192, 192));

// finally, reset resource handle to what it was before
AfxSetResourceHandle(hInstance);


theApp is defined by the Wizard for you and looks something like below:

/////////////////////////////////////////////////////////////////////////////
// The one and only CDLLApp object

CDLLApp theApp;