Hi All
i am creating an application in VS2005 using MFC. My problem is that i want to call dialog through
Dlls.Here i am attaching zip file.Please check it and tell me why i am not getting it.
thanks
Printable View
Hi All
i am creating an application in VS2005 using MFC. My problem is that i want to call dialog through
Dlls.Here i am attaching zip file.Please check it and tell me why i am not getting it.
thanks
Please, describe what problem do you have and what exactly you were "not getting".
Thanks sir
we have two project here one is MYDll and next is Test Dll. In MyDll i have created a modal dialog
derived with CDialog and take a method DoModal here like this
//in Header of MyClass.h
public:
__declspec(dllexport) CString SayHello (CString strName);
__declspec(dllexport) CMyClass();
__declspec(dllexport) virtual ~CMyClass();
void DoModal();
// this is in MyClass.cpp
void CMyClass ::DoModal()
{
CAnand a;
a.DoModal ();
}
Now i want to call this dialog through Dll in My TestDll
In TestDll i have added ExtDllState.h
#ifndef __EXTDLLSTATE_H__
#define __EXTDLLSTATE_H__
class CEXTDLLState
{
public:
CEXTDLLState();
~CEXTDLLState();
protected:
HINSTANCE m_hInstOld;
};
#endif
and ExtDllState.cpp class
static AFX_EXTENSION_MODULE MyDll = { NULL, NULL };
CEXTDLLState::CEXTDLLState()
{
m_hInstOld = AfxGetResourceHandle();
//AfxSetResourceHandle(extensionDLL.hModule);
HINSTANCE hRes=NULL;
hRes=::LoadLibrary ("MyDll.dll");
if(hRes )
AfxSetResourceHandle (hRes );
}
CEXTDLLState::~CEXTDLLState()
{
AfxSetResourceHandle(m_hInstOld);
}
now i am adding TestDllDlg class exact these function
void CTestDLLDlg::OnOK()
{
UpdateData(true);
CString strResult = objMyClass.SayHello(m_edit);
AfxMessageBox (strResult);
//CDialog::OnOK();
}
and
int CTestDLLDlg ::DoModal()
{
CEXTDLLState State;
return CDialog::DoModal();
}
everything is fine but when i debug this i found m_pMainWnd
and debug point reach Winmain.cpp
in thse lines
// Perform specific initializations
if (!pThread->InitInstance())
{
if (pThread->m_pMainWnd != NULL)
{
TRACE(traceAppMsg, 0, "Warning: Destroying non-NULL m_pMainWnd\n");
pThread->m_pMainWnd->DestroyWindow();
}
nReturnCode = pThread->ExitInstance();
goto InitFailure;
}
So. How i can call this dialog in my second project with Dlls
thanks a lot
No, that is not your problem.
What you are trying to do is to call dialog in a dll. and that has nothing to do with your problem that can be described as follow:
I am nor able to start application and I am getting:
Unhandled exception at 0x557562f9 (mfc90d.dll) in TestDLL.exe: 0xC0000005: Access violation reading location 0xfefeff66.
As you can see, your problem is in TestDLL.exe, not in MyDLL.dll.
Did you write this application?
If you did, you must have followed ill advice to use CEXTDLLState before calling DoModal in CTestDLLDlg. This small class swithces resource handle from executable to a dll after loading it, therefore creation of a dialog for CTestDLLDlg object fails in FindResource looking for templare, since template does not exist in a dll.
That is only one problem you have stumble on. Once you remove line that instatiate CEXTDLLState before calling DoModal, main dialog will come up.
Dialog you reques from dll will not. That is a place to instantiate CEXTDLLState. You need to switch resource handle, since without switching FindResource in DoModal for CAnand dialog fails; there is no template for it in TestDLL.exe.
Another thing is inserting dialog after return. This code like that will never be executed.
Thanks Sir
Acutally i have not more idea about MFC. Just i am trying to do this
and i have taken help form this link http://www.********.net/Visual_C_MFC...ension-dll.htm can you please send me a sample application.
so that i can do this and can get my mistake.
thanks
In fact, John kindly gave you a complete explanation. If it's too difficult for you to follow it, I would suggest you to simplify your sample a bit, get it working, and only after that go with something more complex. While you fight with your code you can upload current state of your project to the forum to let other people just fix it here and there. This will be much more effective than asking people to provide you a sample for your very specific case.