Solved

Create CDHtmlDialog in statically linked MFC DLL failed

Posted on 2006-06-29
7
1,077 Views
Last Modified: 2013-11-25
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?
0
Comment
Question by:sunsa
[X]
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
7 Comments
 
LVL 22

Expert Comment

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

-MAHESH
0
 

Author Comment

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

Author Comment

by:sunsa
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.

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.
0
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

by:sunsa
ID: 17016502
Problem solved,
I add
::OleInitialize(NULL);

in InitInstance()
0
 
LVL 22

Expert Comment

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

-MAHESH
0
 
LVL 1

Accepted Solution

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

GhostMod
Community Support Moderator
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…

726 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