I am trying to write an extension for Internet Explorer 11 as a Browser Helper Object in Visual C#. I'm using Visual Studio 2013 on Windows 7. With zilch experience here I've run in to a brick wall trying to get off the ground. I'm not exactly sure how to implement the interface IObjectWithSite for the BHO. I've tried something basic to get me started, but it doesn't work...any ideas?
using System;
using System.Runtime.InteropServices;
using SHDocVw;
using mshtml;
using System.Windows.Forms;
namespace IeAddOnDemo
{
[ComVisible(true),
Guid("9AB12757-BDAF-4F9A-8DE8-413C3615590C"),
ClassInterface(ClassInterfaceType.None)]
public class BHO : IObjectWithSite
{
public void SetSite(object site)
{
System.Diagnostics.Debug.WriteLine("hello");
}
public void GetSite(ref Guid guid, out IntPtr ppvSite)
{
System.Diagnostics.Debug.WriteLine("hello");
ppvSite = new IntPtr();
}
}
}
I can't even get this to write to console. The BHO is being picked up by IE as I've registered it and it's appearing under "Manage Add-Ons" in the Settings menu.
Hopefully with this BHO I'm going to try access IE and then hopefully manipulate the DOM. It's an alien way of doing things for me (I'm used to Eclipse RCP, Linux) so I hope someone can point me in the right direction!
Cheers!
If you see BHO in the list of "Manage Add-Ons" page then it should be working. The operation System.Diagnostics.Debug.WriteLin likely won't work since BHOs are usually restricted to access everything beside the browser itself. Try another thing instead - try to paste method below into the methods GetSite/SetSite methods.
After that if message box is shown - they are invoked and BHO works. Also try to see what IE process are launched in the Task Manager, AFAIK BHO is allocated a separate process.
Regarding DOM manipulation - try samples from articles from CodeProject or other SO answers, e.g. from http://www.codeproject.com/Articles/149258/Inject-HTML-and-JavaScript-into-an-existing-page-w.
Hope that will help.