在MFC dialog调用dll接口动态创建在主dialog显示的webbrowser控件失败!!?

equalman2 2012-04-12 03:19:11
今要定制webbrowser的外观和行为,发现只有使用mfc的静态链接库时才不会导致链接错误,为在exe中用mfc动态库所以将定制webbrowser的代码封装为dll,该代码链接mfc的静态库,而主exe还是链接mfc的动态库。调用dll接口时将mfc的实例句柄和资源句柄传入dll

JWEBBROWSER_API CWnd* __stdcall CreateWebBrowser(HINSTANCE m_hCurrentInstanceHandle,HINSTANCE m_hCurrentResourceHandle,LPCTSTR lpszClassName
, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
{
AfxGetModuleState()->m_hCurrentInstanceHandle=m_hCurrentInstanceHandle;
AfxGetModuleState()->m_hCurrentResourceHandle=m_hCurrentResourceHandle;
//m_htmlAdvertising为派生自cHtmlview的CWebBrowserView类对象
m_htmlAdvertising.Create(lpszClassName,lpszWindowName,dwStyle,rect,pParentWnd,nID,NULL);
return (CWnd*)&m_htmlAdvertising;
}



BOOL CWebBrowserView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// create the view window itself
m_pCreateContext = pContext;
if (!CView::Create(lpszClassName, lpszWindowName,
dwStyle, rect, pParentWnd, nID, pContext))
{
return FALSE;
}

// assure that control containment is on
//AfxEnableControlContainer(); // <- this alters our customization.

RECT rectClient;
GetClientRect(&rectClient);

// create the control window
// AFX_IDW_PANE_FIRST is a safe but arbitrary ID
if (!m_wndBrowser.CreateControl(CLSID_WebBrowser, lpszWindowName,
WS_VISIBLE | WS_CHILD, rectClient, this, AFX_IDW_PANE_FIRST))
{
DestroyWindow();
return FALSE;
}

LPUNKNOWN lpUnk = m_wndBrowser.GetControlUnknown();
HRESULT hr = lpUnk->QueryInterface(IID_IWebBrowser2, (void**) &m_pBrowserApp);
if (!SUCCEEDED(hr))
{
m_pBrowserApp = NULL;
m_wndBrowser.DestroyWindow();
DestroyWindow();
return FALSE;
}

return TRUE;
}

请问
...全文
213 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
oyljerry 2012-04-12
  • 打赏
  • 举报
回复
GetLastError() 查看错误号
equalman2 2012-04-12
  • 打赏
  • 举报
回复
大家来帮忙啊 CView::Create(lpszClassName, lpszWindowName,
dwStyle, rect, pParentWnd, nID, pContext))
这一句内部

CREATESTRUCT cs;
cs.dwExStyle = dwExStyle;
cs.lpszClass = lpszClassName;
cs.lpszName = lpszWindowName;
cs.style = dwStyle;
cs.x = x;
cs.y = y;
cs.cx = nWidth;
cs.cy = nHeight;
cs.hwndParent = hWndParent;
cs.hMenu = nIDorHMenu;
cs.hInstance = AfxGetInstanceHandle();
cs.lpCreateParams = lpParam;

if (!PreCreateWindow(cs))
{
PostNcDestroy();
return FALSE;
}

AfxHookWindowCreate(this);
HWND hWnd = ::CreateWindowEx(cs.dwExStyle, cs.lpszClass,
cs.lpszName, cs.style, cs.x, cs.y, cs.cx, cs.cy,
cs.hwndParent, cs.hMenu, cs.hInstance, cs.lpCreateParams);

hWnd 为NULL!!!
equalman2 2012-04-12
  • 打赏
  • 举报
回复
请问我该怎么做呢 ?

15,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧