Writing IE add-on in C#, VB.NET, C++.
Tips for Internet Explorer 6 and IE 7.
Add-in Express™ |
|
The Use IE6 Compatible Interop Assembly checkbox is checked |
IE version installed on the development PC |
IE versions supported by the add-on |
|
Yes |
IE6 or IE7 or IE8 |
IE6, IE7 and IE8 |
|
No |
IE 6 |
IE6, IE7 and IE8 |
|
No |
IE 7 |
IE 7 and IE8 |
|
No |
IE 8 |
IE8 |
What are interop assemblies (PIA)?
Interop Assemblies provide the compiler with early-binding information on the host application objects, their properties, and methods. All IE versions are almost 100% backward compatible and you can use interops from IE6 to work with IE7 and IE8. Note, in this case, you can access IE7 features using late binding (see the InvokeMember method in MSDN). Obviously, you cannot expect an add-on developed with, say, IE7 interops to work with IE6 because IE6 does not have some events and properties introduced in IE7.
Deploying – shadow copy
The Add-in Express loader uses the ShadowCopy-related properties and methods of the AppDomain class. When you run your add-on, IE loads the Add-in Express loader DLL referenced in the registry. The loader does the following:
- Finds your add-on DLLs in the DLL Cache. If there are no add-on DLLs in the cache, it copies all assemblies to the cache (including dependencies). The cache folder is located in C:\Documents and Settings\<user name>\Local Settings\Application Data\assembly\dl<number>. If all add-on DLLs (including dependencies) already exist in the cache, it compares their versions. If the versions are not the same, it copies new DLLs to the cache.
- Loads the add-on DLLs from the cache.
You can see how the add-on versioning influences the add-on loading. This approach (it is built into .NET, as you can see) allows replacing add-on DLLs when the add-on is loaded. The disadvantage is numerous files located in the cache. As far as we know, Microsoft doesn't provide a solution for this problem. You may think you can remove these files in an add-on’s uninstall custom action. However, this will remove the files from the current profile only.
How do I find the PublicKeyToken of my IE add-on?
You can find it in the setup project (that must be already built). Click on your add-on primary output in the setup project and, in the Properties window, expand the KeyOutput property and see the PublicKeyToken property value.
Deploying localized IE add-ons
IE add-ons are localizable in the same way as any Windows Forms application. But pay attention to the deployment of localized resources – see http://msdn.microsoft.com/en-us/library/y99d1cd3(VS.80).aspx.
Version_info.xml
Version_info.xml contains information about add-on versions available for installation. It may resemble the following:
<?xml version="1.0" encoding="utf-8"?>
<application name="myaddon">
<product language="1033">
<version name="1.0.0" installationUrl="http://127.0.0.1/myaddon/" productCode="{8D0C0293-D91D-40A4-AC5F-5DC640E7784A}" updateType="bootstrapper">
<files bootstrapper="MyAddonSetup">
<file>myaddonsetup.msi</file>
</files>
<preferences>
<showInstallUI>true</showInstallUI>
<showUninstallUI>false</showUninstallUI>
<webPage>
</webPage>
</preferences>
</version>
</product>
</application>
Handling HTML events
Use the Add HTML Events command to add an ADXIEHTMLDocEvents to the module. In the SupportedEvents property of the component, select HTML control type(s) the events of which the component will intercept. Then add event handlers to appropriate events of the component. Every such event (OnClick is an example) provides the eventObject parameter the use of which is demonstrated in the code below:
Private Sub AdxiehtmlDocEvents1_OnClick(ByVal sender As System.Object, _
ByVal eventObject As System.Object, _
ByVal e As AddinExpress.IE.ADXCancelEventArgs) _
Handles AdxiehtmlDocEvents1.OnClick
'System.Diagnostics.Debugger.Launch()
Dim eventObj As mshtml.IHTMLEventObj2 = _
CType(eventObject, mshtml.IHTMLEventObj2)
Dim elem As mshtml.IHTMLElement = _
Me.HTMLDocument.elementFromPoint(eventObj.clientX, eventObj.clientY)
If elem IsNot Nothing Then
If TypeOf elem Is mshtml.IHTMLAnchorElement Then
Dim anchor As mshtml.IHTMLAnchorElement = _
CType(elem, mshtml.IHTMLAnchorElement)
Dim window As MyWindow = New MyWindow(Me.ParentHandle)
If System.Windows.Forms.MessageBox.Show(window, _
"You've clicked the link labelled '" _
+ elem.innerText _
+ "' and pointing to a page at " _
+ anchor.hostname + "." + vbCrLf + vbCrLf + _
"Do you want to continue?", _
Me.ModuleName, MessageBoxButtons.YesNo) _
= MsgBoxResult.No _
Then
e.Cancel = True
End If
End If
End If
End Sub
The MyWindow type above is a simple class implementing the System.Windows.Forms.IWin32Window interface (see the code below). The window handle for MyWindow is supplied by the ParentHandle property of the module that returns the handle (hwnd) of the tab window. Note that you must show messages in this way; otherwise in IE8 RC1 installed on Windows 7 Beta, a message box is displayed below the IE window.
Public Class MyWindow
Implements System.Windows.Forms.IWin32Window
Dim theHandle As IntPtr
Public Sub New(ByVal aHandle As System.IntPtr)
theHandle = aHandle
End Sub
Public ReadOnly Property Handle() As System.IntPtr _
Implements System.Windows.Forms.IWin32Window.Handle
Get
Return theHandle
End Get
End Property
End Class
Note. If your questions are not answered here, please see the HOWTOs pages:
You may also want to download a sample IE add-on with source code.
IE add-on: tabs, windows, threads, instances and messages << |
