CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2002
    Location
    USA
    Posts
    58

    Can anyone help with load Property Sheet and Page that lives in DLL

    I am trying to build a project that loads a Property Sheet and only one page (because of the trouble I am having here) that is in a dll.
    The exe is just a MFC dialog app w/ default dialog class cut out and I insert loaded pSheet from Dll takes over.

    I tried a CDialog in a dll and loaded similar to what I am doing here and it worked.

    The problem is that everything works fine untill I call CPropertySheet:oModal() thur dlg->DoModal();
    in CLoaderApp::InitInstance() and I get a ASSERT(pTemplate != NULL) in CPropertyPage::PreProcessPageTemplate()
    because the Dialog Templete for property Page(pTemplate) equals NULL.

    I cannot say why I need this loading of a pSheet, but I need to.



    my code...


    In my DLL I have SheetDlg.h

    class CSheetDlg : public CPropertySheet
    {
    ...

    CDllDlg m_DllDlg;
    CSheetDlg() : CPropertySheet()
    {
    Construct("SheetDlg", NULL);
    AddPage(&m_DllDlg);
    }
    ...
    };


    __declspec(dllexpott) CSheetDlg SheetDlg;


    ////////////////

    In my exe I have Loader.cpp

    BOOL CLoaderApp::InitInstance()
    {
    ...
    MainDllInstance = ::LoadLibrary("Dll.dll");

    if(MainDllInstance != NULL)
    {
    dlg = (SheetDlg*)GetProcAddress(MainDllInstance, "SheetDlg");
    }

    m_pMainWnd = dlg;
    int nResponse = dlg->DoModal();
    if (nResponse == IDOK)
    {
    // TODO: Place code here to handle when the dialog is
    // dismissed with OK
    }
    else if (nResponse == IDCANCEL)
    {
    // TODO: Place code here to handle when the dialog is
    // dismissed with Cancel
    }

    FreeLibrary(MainDllInstance);
    ...
    }


    ////////////////

    An ASSERT() is false CPropertyPage::PreProcessPageTemplate() in mfc
    because ::FindResource(psp.hInstance,...)(below)(I think) is not able to find IDD_LOADDLL_DIALOG
    because it is looking in my exe resouces and not my dll resouces.

    void CPropertyPage::PreProcessPageTemplate(PROPSHEETPAGE& psp, BOOL bWizard)
    {
    const DLGTEMPLATE* pTemplate;

    if (psp.dwFlags & PSP_DLGINDIRECT)
    {
    pTemplate = psp.pResource;
    }
    else
    {
    HRSRC hResource = ::FindResource(psp.hInstance,
    psp.pszTemplate, RT_DIALOG);
    HGLOBAL hTemplate = LoadResource(psp.hInstance,
    hResource);
    pTemplate = (LPCDLGTEMPLATE)LockResource(hTemplate);
    }

    error-> ASSERT(pTemplate != NULL);// pTemplate does equal NULL
    ...
    }


    ////////////////

    Here the Call stack

    CPropertyPage::PreProcessPageTemplate(_PROPSHEETPAGEA & {...}, int 0) line 201 + 25 bytes
    CPropertySheet::BuildPropPageArray() line 955
    CPropertySheet:oModal() line 779
    CLoaderApp::InitInstance()
    ...
    ////////////////

    I there a way to point to the right resorce?


    Thanks...

    Real World Coding:
    POP& BuyAPop(Money ADollar){...};
    Real World Coding:
         POP& BuyAPop(Money ADollar){...};

  2. #2
    igbrus is offline Elite Member Power Poster
    Join Date
    Aug 2000
    Location
    Los Angeles
    Posts
    4,658

    Re: Can anyone help with load Property Sheet and Page that lives in DLL

    1. dlg = (SheetDlg*)GetProcAddress(MainDllInstance, "SheetDlg"); is absolutely wrong statement

    dlgCreate = ( SheetDlg routine pointer )GetProcAddress(MainDllInstance, "SheetDlg");
    dlg = dlgCreate();
    2. Did you put
    AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
    at SheetDlg

    Rating isn't important...But gurus respect it and keep high

  3. #3
    Join Date
    Jan 2002
    Location
    USA
    Posts
    58

    Re: Can anyone help with load Property Sheet and Page that lives in DLL

    <i>dlg = (SheetDlg*)GetProcAddress(MainDllInstance, "SheetDlg"); is absolutely wrong statement</i>

    should have been
    dlg = (CSheetDlg*)GetProcAddress(MainDllInstance, "SheetDlg");

    <i>AFX_MANAGE_STATE(AfxGetStaticModuleState( ));</i>

    Where should I put AFX_MANAGE_STATE() in my dll.

    And should I be using SheetDlg.DoModal() in a export dll function instead of my exe

    Real World Coding:
    POP& BuyAPop(Money ADollar){...};
    Real World Coding:
         POP& BuyAPop(Money ADollar){...};

  4. #4
    igbrus is offline Elite Member Power Poster
    Join Date
    Aug 2000
    Location
    Los Angeles
    Posts
    4,658

    Re: Can anyone help with load Property Sheet and Page that lives in DLL

    You should put AFX... before sheetdlg construction. I guess you use new. Yes, move DoModal to the DLL seems better

    Rating isn't important...But gurus respect it and keep high

  5. #5
    Join Date
    Jan 2002
    Location
    USA
    Posts
    58

    Re: Can anyone help with load Property Sheet and Page that lives in DLL

    Also the dll is an extension dll and MSDN said I can put AFX_MANAGE_STATE(AfxGetModuleState( )); or maybe it was AFX_MANAGE_STATE(AfxGetAppModuleState( )); in a WndProc() but using MFC Message maps.

    Any help.

    Real World Coding:
    POP& BuyAPop(Money ADollar){...};
    Real World Coding:
         POP& BuyAPop(Money ADollar){...};

  6. #6
    igbrus is offline Elite Member Power Poster
    Join Date
    Aug 2000
    Location
    Los Angeles
    Posts
    4,658

    Re: Can anyone help with load Property Sheet and Page that lives in DLL

    For extension DLL you shouldn't use GetProcAddress and AFX_M.... You should directly export your class and use AfxGet/SetResourceHandle.
    If you wish to use GetProcAddress, use regular MFC DLL instead of extension

    Rating isn't important...But gurus respect it and keep high

  7. #7
    Join Date
    Jan 2002
    Location
    USA
    Posts
    58

    Re: Can anyone help with load Property Sheet and Page that lives in DLL

    I'll try AfxGet/SetResourceHandle() then move to reg dll if not.

    Real World Coding:
    POP& BuyAPop(Money ADollar){...};
    Real World Coding:
         POP& BuyAPop(Money ADollar){...};

  8. #8
    Join Date
    Mar 2010
    Posts
    2

    Re: Can anyone help with load Property Sheet and Page that lives in DLL

    Hello,

    Is any one found solution for this problem? If found then can you pls send me the sample code?

    Thanks in Advance!

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