在网上看到关于IE-dll绑定的文章,使用com组件进行编程,主要方法如下:
1 .建立ALT COM AppWizard,选择dll版本;
2.Menu->Insert->New Alt Object->Simple Object,填入名称FiltreateIE;
3..h文件如下:
// FiltrateIE.h : Declaration of the CFiltrateIE #ifndef __FILTRATEIE_H_ #define __FILTRATEIE_H_ #include "resource.h" // main symbols #include <EXDISP.H> //added #include <MSHTML.H> //added / // CFiltrateIE class ATL_NO_VTABLE CFiltrateIE : public CComObjectRootEx<CComSingleThreadModel>, public CComCoClass<CFiltrateIE, &CLSID_FiltrateIE>, public IObjectWithSiteImpl<CFiltrateIE>, //added public IDispatchImpl<IFiltrateIE, &IID_IFiltrateIE, &LIBID_DLLBINDLib> { public: CFiltrateIE() { } DECLARE_REGISTRY_RESOURCEID(IDR_FILTRATEIE) DECLARE_NOT_AGGREGATABLE(CFiltrateIE) //added DECLARE_PROTECT_FINAL_CONSTRUCT() BEGIN_COM_MAP(CFiltrateIE) COM_INTERFACE_ENTRY(IFiltrateIE) COM_INTERFACE_ENTRY(IDispatch) COM_INTERFACE_ENTRY(IObjectWithSite) //added END_COM_MAP() // IFiltrateIE public: //--below added STDMETHOD(SetSite)(IUnknown *pUnkSite); STDMETHOD(Invoke)(DISPID dispidMember,REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS * pdispparams, VARIANT * pvarResult, EXCEPINFO * pexcepinfo, UINT * puArgErr); private: enum ConnectType {Advise,Unadvise}; BOOL ManageConnection(enum ConnectType action); CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> m_spWebBrowser2; HWND m_hwndIE; DWORD m_dwCookie; BOOL m_bDocComplete; BOOL m_test; }; #endif //__FILTRATEIE_H_
2.cpp 文件如下
// FiltrateIE.h : Declaration of the CFiltrateIE
#ifndef __FILTRATEIE_H_
#define __FILTRATEIE_H_
#include "resource.h" // main symbols
#include <EXDISP.H> //added
#include <MSHTML.H> //added
/
// CFiltrateIE
class ATL_NO_VTABLE CFiltrateIE :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CFiltrateIE, &CLSID_FiltrateIE>,
public IObjectWithSiteImpl<CFiltrateIE>, //added
public IDispatchImpl<IFiltrateIE, &IID_IFiltrateIE, &LIBID_DLLBINDLib>
{
public:
CFiltrateIE()
{
}
DECLARE_REGISTRY_RESOURCEID(IDR_FILTRATEIE)
DECLARE_NOT_AGGREGATABLE(CFiltrateIE) //added
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CFiltrateIE)
COM_INTERFACE_ENTRY(IFiltrateIE)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(IObjectWithSite) //added
END_COM_MAP()
// IFiltrateIE
public: //--below added
STDMETHOD(SetSite)(IUnknown *pUnkSite);
STDMETHOD(Invoke)(DISPID dispidMember,REFIID riid, LCID lcid, WORD wFlags,
DISPPARAMS * pdispparams, VARIANT * pvarResult,
EXCEPINFO * pexcepinfo, UINT * puArgErr);
private:
enum ConnectType {Advise,Unadvise};
BOOL ManageConnection(enum ConnectType action);
CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> m_spWebBrowser2;
HWND m_hwndIE;
DWORD m_dwCookie;
BOOL m_bDocComplete;
BOOL m_test;
};
#endif //__FILTRATEIE_H_
3.在.rgs文件中添加如下代码:
HKLM
{
SOFTWARE
{
Microsoft
{
Windows
{
CurrentVersion
{
Explorer
{
'Browser Helper Objects'
{
ForceRemove{18DF081C-E8AD-4283-A596-FA578C2EBDC3} = s'dllbind'
}
}
}
}
}
}
}
4.编译通过。但存在的问题是,不知道第3步中填写的uuid是否正确。在机器中相应的注册表下有两个表项。但都不是空值。
编译通过,如何测试程序的功能?将相应的DLL文件?启用IE进行测试?