Saturday, June 2, 2007

MFC Resource-only dll


How to create a resource-only dll?



  • create a new Win32 DLL (non-MFC) project and add your resources to the project


  • In project's property pages->Linker->Advanced, Specify the /NOENTRY linker option.
    /NOENTRY prevents the linker from linking a reference to _main into the DLL; this option is required to create a resource-only DLL.




How to use a resource-only dll?


The application that uses the resource-only DLL should call LoadLibrary to explicitly link to the DLL.


//load resource:

HINSTANCE m_hInstResource;
m_strResFilename = _T("DataExchangeRes.dll");
m_hInstResource = ::LoadLibrary(m_strResFilename);
if (NULL != m_hInstResource){
AfxSetResourceHandle(m_hInstResource);
}


//Free Resource:

if (NULL != m_hInstResource) {
VERIFY(FreeLibrary(m_hInstResource));
m_hInstResource = NULL;
}


//Access the resource:



FindResource


LoadResource


FormatMessage


LoadAccelerators


LoadBitmap


LoadCursor


LoadIcon


LoadMenu


LoadString




No comments: