CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2008
    Posts
    63

    Question Dll Dialog not showing

    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
    Attached Files Attached Files

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Dll Dialog not showing

    Please, describe what problem do you have and what exactly you were "not getting".
    Victor Nijegorodov

  3. #3
    Join Date
    Jul 2008
    Posts
    63

    Re: Dll Dialog not showing

    Quote Originally Posted by VictorN View Post
    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 :oModal()
    {
    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 :oModal()
    {

    CEXTDLLState State;

    return CDialog:oModal();

    }

    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

  4. #4
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Dll Dialog not showing

    Quote Originally Posted by anandji05 View Post
    My problem is that i want to call dialog through
    Dlls. . .
    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:

    Quote Originally Posted by anandji05 View Post
    i am creating an application in VS2005 using MFC.
    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.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  5. #5
    Join Date
    Jul 2008
    Posts
    63

    Re: Dll Dialog not showing

    Quote Originally Posted by JohnCz View Post
    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

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Dll Dialog not showing

    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.
    Best regards,
    Igor

  7. #7
    Join Date
    Jul 2008
    Posts
    63

    Re: Dll Dialog not showing

    Quote Originally Posted by Igor Vartanov View Post
    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.
    Thanks Sir.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured