Create CDHtmlDialog in statically linked MFC DLL failed

Posted on 2006-06-29
Medium Priority
Last Modified: 2013-11-25
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)))
      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?
Question by:sunsa
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 22

Expert Comment

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


Author Comment

ID: 17015822
Can you give me some sample codes for this? Thanks,

Author Comment

ID: 17015954
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.

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.

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 17016502
Problem solved,
I add

in InitInstance()
LVL 22

Expert Comment

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


Accepted Solution

GhostMod earned 0 total points
ID: 17047235
Closed, 500 points refunded.

Community Support Moderator

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question