Link to home
Start Free TrialLog in
Avatar of sunsa
sunsa

asked on

Create CDHtmlDialog in statically linked MFC DLL failed

Hi,
My project need use a exe(statically linked MFC) load a dll(statically linked MFC),
and create a CDHtmlDialog in the dll.
I add a CDHtmlDialog to the DLL, "class DHtmlDialogTest : public CDHtmlDialog"
and create dialog at DLL's export function,
"DHtmlDialogTest .Create(IDD_DHtmlDialogTest , CWnd::GetDesktopWindow());"

But when excute DHtmlDialogTest .Create(IDD_DHtmlDialogTest , CWnd::GetDesktopWindow());
enter "dlgdhtml.cpp"'s function "CDHtmlDialog::OnInitDialog()"
at following code inside "CDHtmlDialog::OnInitDialog()"

if (m_pBrowserApp == NULL)
{
     // create the control window
     m_wndBrowser.CreateControl(CLSID_WebBrowser, NULL,
                  WS_VISIBLE | WS_CHILD, rectClient, this, AFX_IDC_BROWSER);
     lpUnk = m_wndBrowser.GetControlUnknown();
     if (FAILED(lpUnk->QueryInterface(IID_IWebBrowser2, (void**) &m_pBrowserApp)))
     {
      m_wndBrowser.DestroyWindow();
      DestroyWindow();
      return TRUE;
     }
}

it will GPF which is get a unhandle exception when excute  
if (FAILED(lpUnk->QueryInterface(IID_IWebBrowser2, (void**) &m_pBrowserApp)))

Maybe because I can't load the resource?
Because I trce the call stack, when enter afxwin2.inl excute following code:
CDialog::Create(ATL_MAKEINTRESOURCE(nIDTemplate), pParentWnd);
ATL_MAKEINTRESOURCE(nIDTemplate) return a bad ptr,

But I can create a CDialog in the same DLL, only can't create a CDHtmlDialog,

Or is there any thing I need to aware when use a exe(statically linked MFC) load a dll(statically linked MFC),
and create a CDHtmlDialog in the dll?
Avatar of mahesh1402
mahesh1402
Flag of India image

have you tried that by using CreateDialogIndirect() instead if CDialog::Create() ?

-MAHESH
Avatar of sunsa
sunsa

ASKER

Can you give me some sample codes for this? Thanks,
Avatar of sunsa

ASKER

Further explain:

Origin problem will GPF which is get a unhandle exception when excute
if (FAILED(lpUnk->QueryInterface(IID_IWebBrowser2, (void**) &m_pBrowserApp)))

the m_wndBrowser is NULL and lpUnk is also NULL.

and:
1. I can create a CDialog in the same DLL above, only can't create a CDHtmlDialog.

2. If use a exe(dynamically link MFC) load a dll(Extension DLL use MFC),
it can do the same thing create a CDHtmlDialog in the dll fine.

Thanks.
Avatar of sunsa

ASKER

Problem solved,
I add
::OleInitialize(NULL);

in InitInstance()
ok you may also use AfxOleInit() in ur applications InitInstance() to initiaklise OLE / COM library

-MAHESH
ASKER CERTIFIED SOLUTION
Avatar of GhostMod
GhostMod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial