Click here to Skip to main content
16,005,281 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Custom controls in an exported DLL Pin
Bartosz Bien6-Mar-03 12:33
Bartosz Bien6-Mar-03 12:33 
GeneralRe: Custom controls in an exported DLL Pin
DREVET Olivier6-Mar-03 13:06
DREVET Olivier6-Mar-03 13:06 
GeneralRe: Custom controls in an exported DLL Pin
Bartosz Bien7-Mar-03 0:33
Bartosz Bien7-Mar-03 0:33 
GeneralRe: Custom controls in an exported DLL Pin
DREVET Olivier7-Mar-03 0:48
DREVET Olivier7-Mar-03 0:48 
GeneralRe: Custom controls in an exported DLL Pin
Bartosz Bien7-Mar-03 1:07
Bartosz Bien7-Mar-03 1:07 
GeneralRe: Custom controls in an exported DLL Pin
DREVET Olivier7-Mar-03 1:21
DREVET Olivier7-Mar-03 1:21 
GeneralRe: Custom controls in an exported DLL Pin
DREVET Olivier7-Mar-03 4:34
DREVET Olivier7-Mar-03 4:34 
GeneralRe: Custom controls in an exported DLL Pin
Bartosz Bien7-Mar-03 4:49
Bartosz Bien7-Mar-03 4:49 
When you are to create the form view, set the resource handle to the DLL one. These are the steps required (file and variable names assumed, use your own):

1. Near the DllMain function in YourDllName.cpp, find a declaration like: AFX_EXTENSION_MODULE YourDLL = { NULL, NULL };

2. In YourDllName.h (if it doesn't exist, create it), declare:
extern AFX_EXTENSION_MODULE YourDLL;

3. Before form creation, set the handle:

HINSTANCE hPrevHandle = AfxGetResourceHandle();<br />
AfxSetResourceHandle(YourDLL);

// TODO: create view here
AfxSetResourceHandle(hPrevHandle);

If the handle is not set to a module where you defined a dialog template, it cannot be loaded and thus creation fails.

Additionally, you may use a class that encapsulates above functionality and restores the original handle in its destructor (when going out of scope):

class CResourceHandler<br />
{<br />
public:<br />
    HINSTANCE m_prevHandle;<br />
<br />
public:<br />
    CResourceHandler(AFX_EXTENSION_MODULE &module);<br />
    {<br />
        m_prevHandle = AfxGetResourceHandle()<br />
        AfxSetResourceHandle(module.hModule);<br />
    }<br />
<br />
    CResourceHandler(HINSTANCE &handle)<br />
    {<br />
        m_prevHandle = AfxGetResourceHandle();<br />
        AfxSetResourceHandle(handle);<br />
    }<br />
<br />
    virtual ~CResourceHandler()<br />
    {<br />
        AfxSetResourceHandle(m_prevHandle);<br />
    }<br />
};


4. With the class, the creation code simplifies as follows:
<br />
void CreateMyFormView()<br />
{<br />
    CResourceHandler rh(YourDLL.hModule);

// TODO: create view here
}

Of course, the CreateMyFormView() function has to be located in a DLL.

Regards,
BB
GeneralDynamic creation (instanciation) of classes Pin
dherrero6-Mar-03 8:35
dherrero6-Mar-03 8:35 
GeneralRe: Dynamic creation (instanciation) of classes Pin
Ravi Bhavnani6-Mar-03 8:37
professionalRavi Bhavnani6-Mar-03 8:37 
GeneralRe: Dynamic creation (instanciation) of classes Pin
dherrero6-Mar-03 12:11
dherrero6-Mar-03 12:11 
GeneralAdd about to system menu in dialog box Pin
jimNLX6-Mar-03 8:27
jimNLX6-Mar-03 8:27 
GeneralRe: Add about to system menu in dialog box Pin
Ravi Bhavnani6-Mar-03 8:35
professionalRavi Bhavnani6-Mar-03 8:35 
GeneralRe: Add about to system menu in dialog box Pin
jimNLX6-Mar-03 8:37
jimNLX6-Mar-03 8:37 
GeneralRe: Add about to system menu in dialog box Pin
jimNLX6-Mar-03 9:12
jimNLX6-Mar-03 9:12 
QuestionDiffernance between MFC extension DL L and regular mfc dll? Pin
clintsinger6-Mar-03 8:17
clintsinger6-Mar-03 8:17 
AnswerRe: Differnance between MFC extension DL L and regular mfc dll? Pin
Bartosz Bien6-Mar-03 12:35
Bartosz Bien6-Mar-03 12:35 
GeneralTransparent Icons Pin
jimNLX6-Mar-03 8:17
jimNLX6-Mar-03 8:17 
GeneralRe: Transparent Icons Pin
DREVET Olivier7-Mar-03 3:10
DREVET Olivier7-Mar-03 3:10 
GeneralSDK & DDK Pin
jucanpo6-Mar-03 7:58
jucanpo6-Mar-03 7:58 
GeneralRe: SDK & DDK Pin
Chris Richardson6-Mar-03 9:35
Chris Richardson6-Mar-03 9:35 
GeneralLines count Pin
Anonymous6-Mar-03 7:49
Anonymous6-Mar-03 7:49 
GeneralRe: Lines count Pin
Christian Graus6-Mar-03 9:48
protectorChristian Graus6-Mar-03 9:48 
GeneralInternet protocols Pin
Mazdak6-Mar-03 7:45
Mazdak6-Mar-03 7:45 
GeneralRe: Internet protocols Pin
Brian D6-Mar-03 8:27
Brian D6-Mar-03 8:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.