Internet Explorer Add On in c#

Browser Helper Object (BHO) with managed Code

As Basic Example I use "IE Browser Helper Object demo (CSBrowserHelperObject)"

I downloaded the Source, Compiled it with VS2010 and installed Both 32 and 64 bit versions. My first Modification was to write the HTML in DocumentComplete Event. Trying to debug my Code, my Breakpoints did not work. with Google, I found "The breakpoint will not currently be hit. No symbols have been loaded for this document. Comments (285) | Share". In my case Breakpoints work when I copy the .dll and .pdb in the Installationdirectory (c:\program files...) and attach VS to the IExplore Processes. Next Problem I had, was to write to Disk. IE runs in Enhanced Protected Mode. For Writing I hav to use a Directory with low integrity mandatory label. Usually we should write into IE.s Temporary Internet Files Directory. To get this, I use string tempFolder = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);

Next Step was to manipulate a specific HTML Element.

DispHTMLDocument dispDoc = this.document as DispHTMLDocument;

object o = dispDoc.getElementById("lga"); // Element in www.google.de

To find out the Type: string sTypeName = o.GetType().FullName;

When I use this Type, I get Errors because I have to use the appropriate Interfaces.

WRONG: HTMLDivElementClass oDiv = o as HTMLDivElementClass

Working: HTMLDivElement oDiv = o as HTMLDivElement;

The Object implements more general Interfaces also. So I can use HTMLHtmlElement oHTML = o as HTMLHtmlElement;

To Manipulate the DOM I used oHTML.innerHTML ="<div>Das ist Text aus dem BHO</div>";

Communication from JScript to my Browser Helper Object

First try: I Implement this: Calling C# BHO methods from JavaScript. For this I had to Convert my Project to .NET 4.0. This did not work properly, so I had to fix the References in the .csprj File manually. With proper References I got my Project compiled. Calling my BHO from JScript still did not work. it turned out, that a cannot obtain the parentWindow of the given HTMLDocument in onDocumentComplete Event. I found via Google, that I had to retrieve HTMLWindow and its parentWindow in the same Thread. That Thread has to be a Thread with STA Threading Model (Running a JavaScript function in an instance of Internet Explorer). Now I get the onDocumentCompleteEvent. I can attach an Object containing my c# Functions and Call this extension Object from JScript. One Problem is still remaining. I am missing a Document Complete in a Browser Refresh.



© Willi Neuner 2019 Impressum