As we know, if you want to launch a dialog from a dll, you have to call AFX_MANAGE_STATE to switch module state from current module state to dll module state. Here is the code,
Now if I want to launch another dialog called CYourDialog from CMyDialog and CYourDialog is defined from different module state, then DoModal would fail for CYourDialog. Is there any way to make DoModal work for CYourDialog in this case? Thanks.
You must add the AFX_MANAGE_STATE macro at the beginning of all the exported functions in regular DLLs that dynamically link to MFC to set the current module state to the one for the DLL. This is done by adding the following line of code to the beginning of functions exported from the DLL:
Now if I want to launch another dialog called CYourDialog from CMyDialog and CYourDialog is defined from different module state, then DoModal would fail for CYourDialog. Is there any way to make DoModal work for CYourDialog in this case? Thanks.
You should set the module state correctly before loading any resources from a DLL, so also before you create the second dialog.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
You should set the module state correctly before loading any resources from a DLL, so also before you create the second dialog.
That is exactly my question actually. In my case, Basically CMyDialog and CYourDialog exist in different module states. CMyDialog is not dismissed yet when CYourDialog needs to be launched. So in order to launch CYourDialog, I need to switch the module state from CMyDialog to CYourDialog. But I don't know what to do to achieve that. Any idea how to do that? Thanks.
That is exactly my question actually. In my case, Basically CMyDialog and CYourDialog exist in different module states. CMyDialog is not dismissed yet when CYourDialog needs to be launched. So in order to launch CYourDialog, I need to switch the module state from CMyDialog to CYourDialog. But I don't know what to do to achieve that. Any idea how to do that? Thanks.
You cannot set the module state to a dialog, you set it to the instance handle of a library. Whenever you load resources from a DLL (e.g. create a dialog, which loads the dialog template from the resources), the module state needs to be set to the instance handle of that library. After the resources have been loaded, you simply set it back to the previous value. This is what AFX_MANAGE_STATE does (resetting the instance handle at scope exit.
When you use an extension DLL, the story is different. See the MSDN docs.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
The sample goes. Resource only DLL includes IDD_YOUR dialog template. Regular DLL includes IDD_MY dialog template, but implements both classes, CMyDialog and CYourDialog. Hope this close enough to what you're trying to implement.
The sample goes. Resource only DLL includes IDD_YOUR dialog template. Regular DLL includes IDD_MY dialog template, but implements both classes, CMyDialog and CYourDialog. Hope this close enough to what you're trying to implement.
Thanks for your sample. Actually CMyDialog and CYourDialog are defined in two different dll. Basically what happens is that an exe launches CMyDialog defined in MyDll.dll and then when CMyDialog is NOT dismissed, CYourDialog is launched from defined in YourDll.dll. I would really appreciate it if you can post a sample by using MFC. Thank you very much!
You cannot set the module state to a dialog, you set it to the instance handle of a library. Whenever you load resources from a DLL (e.g. create a dialog, which loads the dialog template from the resources), the module state needs to be set to the instance handle of that library. After the resources have been loaded, you simply set it back to the previous value. This is what AFX_MANAGE_STATE does (resetting the instance handle at scope exit.
When you use an extension DLL, the story is different. See the MSDN docs.
Its interesting and , I feel that you want to just check out all possibilities in MFC and VC++ .
Anyways,
Your scenarios is Application A loads dll D1 contains dialog "Mydialog"
then dll D1 loads D2 that contains "YourDialog".
Now App is able to load MyDialog from D1 and you want to load YourDialog from D2 in the code of D1.
I agree to the solutions given by Igor , Victor and all others.
Apart from that just one suggestion is instead of doing DOModal() on YourDialog try to invoke it as modal less.
or may be invoking both the dialogs modal less.
I know I have to do it within my dll. But the problem is that in my case, the template for CYourDialog exists outside the dll. So within the dll, if I want to launch CYourDialog I need to switch the module state from dll to CYourDialog. But I don't know how to do it. Any idea? Thanks.
Now I like to approach this dialog launching thing step by step. I am not clear conceptually on this topic so please bear with me. First of all, I attached a project. In this project, an executable tries to launch a dialog defined in a dll. Unfortunately I got a linker error "error LNK2019: unresolved external symbol "public: virtual __thiscall CMyDialog::~CMyDialog(void)" (??1CMyDialog@@UAE@XZ) referenced in function "public: void __thiscall CtestMFCExtensionDlg::OnBnClickedStart(void)" (?OnBnClickedStart@CtestMFCExtensionDlg@@QAEXXZ)". I couldn't figure out why. Please help me fix this issue first. Thank you very much!
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.