Solved

Create CDHtmlDialog in statically linked MFC DLL failed

Posted on 2006-06-29
7
1,069 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
  • 3
  • 2
7 Comments
 
LVL 22

Expert Comment

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

-MAHESH
0
 

Author Comment

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

Author Comment

by:sunsa
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:sunsa
Comment Utility
Problem solved,
I add
::OleInitialize(NULL);

in InitInstance()
0
 
LVL 22

Expert Comment

by:mahesh1402
Comment Utility
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
Comment Utility
Closed, 500 points refunded.

GhostMod
Community Support Moderator
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now