在 dll 的 Dialog 內嵌個 WebBrowser 元件會有問題.

2006/11/02  ~ 阿亮 ~

Case: 在 dll 內包 WebBrowser 元件會造成當掉?


Platform: Visual Studio 2005.

Using MFC to Host a WebBrowser Control  所述,將 WebBrowser 嵌在一個 Dialog,而這整個包在一個 dll 內供呼叫,會有當在下面這行的情形:

File: f:\rtm\vctools\vc7libs\ship\atlmfc\src\mfc\occcont.cpp
Line: 950

而且會有類似下述的錯誤訊息,

CoCreateInstance of OLE control {8856F961-340A-11D0-A96B-00C04FD705A2} failed.

/>>> Result code: 0×800401f0

/>>> Is the control is properly registered?

Warning: Resource items and Win32 Z-order lists are out of sync. Tab order may be not defined well.

根據此頁 ,我試的結論下面這個是對的

The error code is 'CO_E_NOTINITIALIZED'. You have to call
'CoInitialize( NULL);' before creating the control (if you're using
MFC, the call is 'AfxOleInit();')

雖然我的例子是 MFC 的程式(來源文章說要用 'AfxOleInit();'),我在 Dialog 的建構函數加 'CoInitialize( NULL);',而在解構函數加 'CoUninitialize()' 即可行,。而 CoInitialize 的作用是會使 COM/OLE 可以 Work 的;但蠻奇怪的是,若這個 COM/OLE 不在 dll 內的話,則不需要 CoInitialize( NULL) 也可 Work?

有空再搞懂 COM/OLE 在做啥好了,至少短期目標達成

加入書籤:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • Furl
  • Hemidemi
  • MyShare
  • Technorati
  • YahooMyWeb
  • BlogMemes Cn
  • Haohao
  • MisterWong
  • Netscape
  • Slashdot
  • funP

相關文章

  • No Related Post

歡迎留言

敝站會審核留言的適宜性,您的留言可能會較晚發佈,而且小弟保留刪除的權利!!

以下圖像請用滑鼠「拖曳」到編輯區即可用