IE的DLL绑定

  1. 我查阅了一些资料,但写关于IE的DLL绑定的文章并不多,而且,写得不是很清楚。为此,我想介绍一下,这个方法:
  2. 基础知识:VC COM,(ALT方法来做)
  3. IE的启动过程:
  4. 当IE的实例启动的时候,他会在注册表中寻找一个CLSID,具体位置在
  5. HKEY_LOCALL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionExplorerBrowser Helper Objects
  6. 当这里存在一CLSID时,IE会建立一个对象的实例。比如:{B5D4581D-ED6A-4905-A267-25BAF7BE79C1}假如这个看不懂,您能够去找一下COM研发的书。
  7. 研发实例:
  8. VC建立工程,ALT COM AppWizard 注意是DLL.
  9. 建立一个新的类,一定要是ALT
  10. 在菜单,Insert>New ALT Object:Simple Object
  11. 修改并实现方法
  12. // FiltrateIE.h : Declaration of the CFiltrateIE
  13. #ifndef __FILTRATEIE_H_
  14. #define __FILTRATEIE_H_
  15. #include "resource.h" // main symbols
  16. #include <ExDisp.h> //这里必须加上这两个头文档
  17. #include <msHtml.h>
  18. #define MAX_DOCUMENTS 50
  19. /
  20. // CFiltrateIE
  21. class ATL_NO_VTABLE CFiltrateIE :
  22. public CComObjectRootEx<CComSingleThreadModel>,
  23. public CComCoClass<CFiltrateIE, &CLSID_FiltrateIE>,
  24. public IObjectWithSiteImpl<CFiltrateIE>,//加入这个,以继承该接口
  25. public IDispatchImpl<IFiltrateIE, &IID_IFiltrateIE, &LIBID_SAFEIELib>
  26. {
  27. public:
  28. CFiltrateIE()
  29. {
  30. }
  31. DECLARE_REGISTRY_RESOURCEID(IDR_FILTRATEIE)
  32. DECLARE_NOT_AGGREGATABLE(CFiltrateIE)
  33. DECLARE_PROTECT_FINAL_CONSTRUCT()
  34. BEGIN_COM_MAP(CFiltrateIE)
  35. COM_INTERFACE_ENTRY(IFiltrateIE)
  36. COM_INTERFACE_ENTRY(IDispatch)
  37. COM_INTERFACE_ENTRY(IObjectWithSite)//加入
  38. END_COM_MAP()
  39. // IFiltrateIE
  40. public
  41. //下面两个方法必须实现
  42. STDMETHOD(SetSite)(IUnknown *pUnkSite);
  43. STDMETHOD(Invoke)(DISPID dispidMember,REFIID riid, LCID lcid, WORD wFlags,
  44. DISPPARAMS * pdispparams, VARIANT * pvarResult,
  45. EXCEPINFO * pexcepinfo, UINT * puArgErr);
  46. private:
  47. //下面一个方法必须实现
  48. enum ConnectType {Advise,Unadvise};
  49. BOOL ManageConnection(enum ConnectType action);
  50. CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> m_spWebBrowser2;
  51. HWND m_hwndIE;
  52. DWORD m_dwCookie;
  53. BOOL m_bDocComplete;
  54. BOOL m_test;
  55. };
  56. #endif //__FILTRATEIE_H_
  57. // FiltrateIE.cpp : Implementation of CFiltrateIE
  58. #include "stdafx.h"
  59. #include "SafeIE.h"
  60. #include "FiltrateIE.h"
  61. #include <tchar.h>
  62. #include <ExDisp.h>
  63. #include <ExDispID.h>
  64. #include <comdef.h>
  65. #include <Commctrl.h>
  66. #include <strstrea.h>
  67. /
  68. // CFiltrateIE
  69. BOOL CFiltrateIE::ManageConnection(enum ConnectType action)
  70. {
  71. if (!m_spWebBrowser2)
  72. return S_OK;
  73. HRESULT hr;
  74. CComQIPtr<IConnectionPointContainer, &IID_IConnectionPointContainer> spCPContainer(m_spWebBrowser2);
  75. if (spCPContainer != NULL)
  76. {
  77. CComPtr<IConnectionPoint> spConnectionPoint;
  78. hr = spCPContainer->FindConnectionPoint(DIID_DWebBrowserEvents2, &spConnectionPoint);
  79. if (SUCCEEDED(hr))
  80. {
  81. if (action == Advise)
  82. // Advise the client site that we want to sink events
  83. hr = spConnectionPoint->Advise((IDispatch*)this, &m_dwCookie);
  84. else
  85. // Remove us from the list of active sinks
  86. hr = spConnectionPoint->Unadvise(m_dwCookie);
  87. }
  88. }
  89. return (SUCCEEDED(hr));
  90. }
  91. STDMETHODIMP CFiltrateIE::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags,
  92. DISPPARAMS* pDispParams, VARIANT* pvarResult,
  93. EXCEPINFO* pExcepInfo, UINT* puArgErr)
  94. {
  95. m_test=TRUE;
  96. if (!pDispParams)
  97. return E_INVALIDARG;
  98. CComPtr<IDispatch> spDisp;
  99. HRESULT hr;
  100. switch (dispidMember)
  101. {
  102. case DISPID_BEFORENAVIGATE2:
  103. m_bDocComplete = FALSE;
  104. m_spWebBrowser2 = pDispParams->rgvarg[6].pdispVal; 
  105. hr = m_spWebBrowser2->get_Document(&spDisp);
  106. if (SUCCEEDED(hr))
  107. {
  108. CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> spHTML;
  109. spHTML = spDisp;
  110. // if (spHTML)
  111. // RemoveDocument(spHTML);
  112. }
  113. break;
  114. case DISPID_NAVIGATECOMPLETE2:
  115. //
  116. /* if (m_spWebBrowser2){
  117. _bstr_t bsAddress=m_spWebBrowser2->GetLocationURL();
  118. LPCTSTR str1,str2;
  119. str1="SolarSafe.htm";
  120. str2=(LPCTSTR)bsAddress;
  121. if (strstr(str2,str1)!=NULL)
  122. {
  123. ShellExecute((HWND)m_spWebBrowser2->HWND,"open","C:/solarsafe.htm",NULL,NULL,SW_SHOWNORMAL);
  124. }
  125. */ 
  126. break;
  127. // [0]: New status bar text - VT_BSTR
  128. //
  129. /*
  130. case DISPID_STATUSTEXTCHANGE:
  131. break;
  132. */
  133. // [0]: Maximum progress - VT_I4
  134. // [1]: Amount of total progress - VT_I4
  135. //
  136. /*
  137. case DISPID_PROGRESSCHANGE:
  138. break;
  139. */
  140. // [0]: Document URL - VT_BYREF|VT_VARIANT
  141. // [1]: An object that evaluates to the top-level or frame
  142. // WebBrowser object corresponding to the event.
  143. case DISPID_DOCUMENTCOMPLETE:
  144. // Temporarily disable keyboard hook
  145. if(m_test)
  146. {//ShellExecute(m_hwndIE,"open","C:/solarsafe.htm",NULL,NULL,SW_SHOWNORMAL);
  147. MessageBox(m_hwndIE, "AAAA", "A", MB_OK );
  148. // m_spWebBrowser2->Quit();
  149. m_test=FALSE;
  150. }
  151. // Fill in form if necessary
  152. m_spWebBrowser2 = pDispParams->rgvarg[1].pdispVal;
  153. // Get the WebBrowser’s document object
  154. hr = m_spWebBrowser2->get_Document(&spDisp);
  155. if (SUCCEEDED(hr))
  156. CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> spHTML;
  157. spHTML = spDisp;
  158. // if (spHTML && DoFillIn(spHTML))
  159. // AddDocument(spHTML);
  160. }
  161. m_bDocComplete = TRUE;
  162. // Temporarily disable keyboard hook
  163. break;
  164. // No parameters
  165. /*
  166. case DISPID_DOWNLOADBEGIN:
  167. break;
  168. */
  169. // No parameters
  170. /*
  171. case DISPID_DOWNLOADCOMPLETE:
  172. break;
  173. */
  174. // [0]: Enabled state - VT_BOOL
  175. // [1]: Command identifier - VT_I4
  176. //
  177. /*
  178. case DISPID_COMMANDSTATECHANGE:
  179. break;
  180. */
  181. // [0]: Address of cancel flag - VT_BYREF|VT_BOOL
  182. //
  183. /*
  184. case DISPID_NEWWINDOW2:
  185. break;
  186. */
  187. // [0]: Document title - VT_BSTR
  188. // [1]: An object that evaluates to the top-level or frame
  189. // WebBrowser object corresponding to the event.
  190. //
  191. /*
  192. case DISPID_TITLECHANGE:
  193. break;
  194. */
  195. // [0]: Name of property that changed - VT_BSTR
  196. //
  197. /*
  198. case DISPID_PROPERTYCHANGE:
  199. break;
  200. */
  201. // [0]: Address of cancel flag - VT_BYREF|VT_BOOL 
  202. //
  203. case DISPID_ONQUIT:
  204. // Unregister the keyboard hook previously installed
  205. // for this instance.
  206. ManageConnection(Unadvise);
  207. break;
  208. default:
  209. break;
  210. }
  211. return S_OK;
  212. }
  213. STDMETHODIMP CFiltrateIE::SetSite(IUnknown *pUnkSite)
  214. {
  215. if (pUnkSite != NULL)
  216. {
  217. // Query pUnkSite for the IWebBrowser2 interface.
  218. m_spWebBrowser2 = pUnkSite;
  219. if (m_spWebBrowser2)
  220. {
  221. m_spWebBrowser2->get_HWND((long*) &m_hwndIE);
  222. // We’ll need the this pointer later when the keyboard
  223. // hook will be called.
  224. // if (!AddInstance(m_hwndIE, this, GetCurrentThreadId()))
  225. // FormWhizError(IDS_ERROR_TOOMUCHWINDOWS, errError);
  226. // Connect to the browser in order to handle events.
  227. if (!ManageConnection(Advise))
  228. MessageBox(m_hwndIE, "AAAA", "A", MB_OK );
  229. // FormWhizError(IDS_ERROR_SINKINGFAILED, errError);
  230. }
  231. }
  232. return S_OK;
  233. }
  234. 找到.rgs文档,加入
  235. HKLM
  236. {
  237. SOFTWARE
  238. {
  239. Microsoft
  240. Windows
  241. {
  242. CurrentVersion
  243. {
  244. Explorer
  245. {
  246. ’Browser Helper Objects’
  247. {
  248. ForceRemove {B5D4581D-ED6A-4905-A267-25BAF7BE79C1} = s ’SafeIE Utility’
  249. }
  250. }
  251. }
  252. }
  253. }
  254. }
  255. }
  256. 上边的{B5D4581D-ED6A-4905-A267-25BAF7BE79C1}在这个文档中能够找到,注意,您做的CSLID肯定不相同
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值