IE Programming --- DLL Binding

zhaozj2021-02-08  245

IE Programming --- DLL Binding

Gu Jianhui (http://solarsoft.126.com)

I have reviewed some information, but there are not many articles about the DLL binding of IE, and it is not very clear. To this end, I want to introduce this method:

Basic knowledge: VC COM, (Alt method)

The startup process of IE:

When the instance of IE is started, it will look for a CLSID in the registry, the specific location is

HKEY_LOCALL_MACHINE / SOFTWARE / Microsoft / Windows / CurrentVersion / Explorer / Browser Helper Objects

When there is a CLSID here, IE will establish an example of an object. For example: {B5D4581D-ED6A-4905-A267-25BAF7BE79C1} If this is not understood, you can find a book developed.

Development example:

VC established project, Alt Com appwizard Note is a DLL.

Establish a new class, must be Alt

In the menu, INSERT> New Alt Object: Simple Object

Modify and implement

// filtrateie.h: Declaration of the cfiltrateie

#ifndef __filtrateie_h_

#define __filtrateie_h_

#include "resource.h" // main symbols

#include // Here you must add these two header files

#include

#define max_documents 50

/

// cfiltrateie

Class ATL_NO_VTABLE CFILTRATEIE:

Public CComobjectrootex ,

Public ccomcoclass ,

Public IObjectWithsiteImpl , // Add this to inherit the interface

Public IDispatchImpl

{

PUBLIC:

Cfiltrateie ()

{

}

DECLARE_REGISTRY_RESOURCEID (iDR_Filtrateie)

Declare_not_aggregatable (cfiltrateie)

Declare_protect_final_construct ()

Begin_COM_MAP (CFILTRATEIE)

COM_ITERFACE_ENTRY (ifiltrateie)

COM_ITERFACE_ENTRY (Idispatch)

COM_INTERFACE_ENTRY (IOBJECTWITHSITE) // Join

END_COM_MAP ()

// ifiltrateie

public

// The following two methods must be implemented

StdMethod (IUNKNOWN * PUNKSITE);

StdMethod (Invoke) (Dispid Dispidmember, Refiid Riid, LCID LCID, Word WFLAGS,

Dispparams * Pdispparams, Variant * Pvarresult,

Excepinfo * pEXCEPINFO, UINT * PUARGERR);

Private:

// A method must be implemented

ENUM CONNECTTYPE {Advise, Unadvise}; Bool ManageConnection (Enum ConnectType Action);

CCOMQIPTR M_SPWebBrowser2;

HWND M_HWNDIE;

DWORD M_DWCOOKIE;

BOOL M_BDOCCOMPLETE;

BOOL M_TEST;

}

#ENDIF / / __ICRATEIE_H_

// Filtrateie.cpp: Implementation of Cfiltrateie

#include "stdafx.h"

#include "safeie.h"

#include "filtrateie.h"

#include

#include

#include

#include

#include

#include

/

// cfiltrateie

Bool Cfiltrateie :: ManageConnection (Enum ConnectType Action)

{

IF (! m_spwebbrowser2)

Return S_OK;

HRESULT HR;

CCOMQIPTR spcpcontainer (m_spwebbrowser2);

IF (spcpcontainer! = NULL)

{

CComptr spConnectionPoint;

HR = spcpcontainer-> FindConnectionPoint (DIID_DWEBBBROWSEREVENTS2, & SPCONNECTIONPOINT);

En (ac))

{

IF (action == advise)

// Advise the Client Site That We want to sink events

HR = SPConnectionPoint-> Advise (iDispatch *), & m_dwcookie;

Else

// Remove US from the list of active sinks

HR = SPCONNECTIONPOINT-> Unadvise (m_dwcookie);

}

}

Return (Succeeded (HR));

}

StdMethodimp CFILTRATEIE :: Invoke (Dispid Dispidmember, Refiid Riid, LCID LCID, Word WFLAGS,

Dispparams * Pdispparams, Variant * Pvarresult,

Excepinfo * pEXCEPINFO, UINT * PUARGERR)

{

m_test = true;

IF (! pdispparams)

Return E_INVALIDARG;

CComptr spdisp;

HRESULT HR;

Switch (Dispidmember)

{

Case Dispid_beforenaviGate2:

m_bdoccomplete = false;

M_spwebbrowser2 = pdispparams-> rgvarg [6] .pdispval; hr = m_spwebbrowser2-> get_document (& SPDISP);

En (ac))

{

CCOMQIPTR SPHTML;

SPHTML = SPDISP;

// if (SPHTML)

// RemoveDocument (SPHTML);

}

Break;

Case Dispid_naviGateComplete2:

//

/ * If (m_spwebbrowser2) {

_BSTR_T BSADDRESS = m_spwebbrowser2-> getlocationURL ();

LPCTSTR STR1, STR2;

Str1 = "solarsafe.htm";

Str2 = (lpctstr) BSADDRESS;

IF (str2, str1)! = NULL)

{

Shellexecute ((hwnd) m_spwebbrowser2-> hwnd, "open", "c: //solarsafe.htm", null, null, sw_shownormal;

}

* /

Break;

// [0]: New Status bar text - vt_bstr

//

/ *

Case Dispid_StatusTextChange:

Break;

* /

// [0]: maximum progress - vt_i4

// [1]: Amount of Total Progress - VT_i4

//

/ *

Case Dispid_ProgressChange:

Break;

* /

// [0]: Document URL - VT_BYREF | VT_VARIANT

// [1]: an Object That Evaluates to the top-level or frame

// WebBrowser Object Corresponding to the event.

Case Dispid_DocumentComplete:

// Temporarily Disable Keyboard Hook

IF (m_test)

{//SHELLEXECUTE (M_HWndie, "open ", "c://solarsafe.htm" ,null, null ,sw_shownormal);

MessageBox (M_HWndie, "AAAA", "A", MB_OK);

// m_spwebbrowser2-> quit ();

m_test = false;

}

// Fill in form if nesery

m_spwebbrowser2 = pdispparams-> rgvarg [1] .pdispval;

// Get the WebBrowser's Document Object

HR = m_spwebbrowser2-> get_document (& SPDISP);

En (ac))

{

CCOMQIPTR SPHTML;

SPHTML = SPDISP;

// if (Sphtml && Dofillin (SPHTML))

// addDocument (SPHTML);

m_bdoccomplete = true;

// Temporarily Disable Keyboard Hook

Break;

// no parameters

/ *

Case Dispid_Downloadbegin:

Break;

* /

// no parameters

/ *

Case Dispid_downloadlineComplete:

Break;

* /

// [0]: Enabled State - VT_BOOL

// [1]: Command Identifier - VT_i4

//

/ *

Case Dispid_CommandStateChange:

Break;

* /

// [0]: Address of cancel flag - vt_byref | vt_bool

//

/ *

Case Dispid_newwindow2:

Break;

* /

// [0]: Document Title - VT_BSTR

// [1]: an Object That Evaluates to the top-level or frame

// WebBrowser Object Corresponding to the event.

//

/ *

Case Dispid_titlechange:

Break;

* /

// [0]: Name of Property That Changed - VT_BSTR

//

/ *

Case Dispid_PropertyChange:

Break;

* /

// [0]: Address of cancel flag - vt_byref | vt_bool

//

Case Dispid_onquit:

// unregister the keyboard hook previously installed. INSTALED HOOK PREVIOSTALLED

// for this installation.

ManageConnection (unadvise);

Break;

DEFAULT:

Break;

}

Return S_OK;

}

STDMETHODIMP CFILTRATEIE :: Setsite (IUNKNOWN * PUNKSITE)

{

IF (Punksite! = NULL)

{

// query punksite for the iWebBrowser2 interface.

m_spwebbrowser2 = punksite;

IF (m_spwebbrowser2)

{

m_spwebbrowser2-> get_hwnd ((long *) & m_hwndie);

// We'll Need The this Pointer Later When THE Keyboard

// hook will be caled.

// if (! Addinstance (m_hwndie, this, getcurrentthreadid ())))

// FormWhizError (IDS_ERROR_TOOMUCHWINDOWS, ErroRror);

// Connect To The Browser in Order to Handle Events.

if (! ManageConnection (Advise))

MessageBox (M_HWndie, "AAAA", "A", MB_OK);

// FormWhizError (IDS_ERROR_SINKINGFAILED, ErroRror);

}

}

Return S_OK;

}

Find .RGS file, join

HKLM

{

Software

{

Microsoft

{

Windows

{

CurrentVersion {

Explorer

{

'Browser Helper Objects'

{

Forceremove {B5D4581D-ED6A-4905-A267-25BAF7BE79C1} = S 'Safeie Utility'

}

}

}

}

}

}

}

The {B5D4581D-ED6A-4905-A267-25BAF7BE79C1} can be found in this file, pay attention, you do CSLID is definitely different.

Everything is OK, try it, you can first look at it, this project code

转载请注明原文地址:https://www.9cbs.com/read-2538.html

New Post(0)