As I suggested in https://learn.microsoft.com/en-us/answers/questions/664560/trying-to-include-an-mfc-dialog-from-a-library-int.html if you want to re-use your custom MFC dialogs in multiple MFC projects place them in an MFC Extension DLL.
Which is the best way to use an mfc class dialog as library from a project to another?
Hello. I have two projects. Project A which is an MFC Application (generated from an API wizard) that I need to have only one dialog and call the rest of dialogs from Project B.
When I include the MFC dialog class header and the source file application runs without a problem.
#include "CTestDlg.h"
#include "CTestDlg.cpp"
If I include .obj file from linker settings application thow an exception in this function:
AFXWIN_INLINE HINSTANCE AFXAPI AfxGetInstanceHandle()
{ ASSERT(afxCurrentInstanceHandle != NULL);
return afxCurrentInstanceHandle; }
I run this code in project A:
AFX_MANAGE_STATE(AfxGetStaticModuleState());
HINSTANCE prevRes = AfxGetResourceHandle();
HINSTANCE hRes = NULL;
hRes = LoadLibrary(_T("M:\\AS\\TestProjects\\AddIn\\x64\\Debug\\Dialogs.dll"));
if (hRes)
{
AfxSetResourceHandle(hRes);
}
CTestDlg dlg;
dlg.DoModal();
I tested with two defaults mfc applications and I had no problem, even if I include dialog classes from linker. From the debuggin that I did, I think is something related to the resource files.