Hello Joe,
Here is one VB.NET sample for your reference:
This is a brief description of the sample
1. Defines the IObjectWithSite COM Interface
2. Implements the IObjectWithSite COM Interface
3. SetSite method receives IUnknown for COM object that implements
IWebBrowser2 and Internet Explorer
Set default Browser's UI and behavior in SetSite
4. Declares RegisterServer Function than handles the registration of the
DLL- When regasm is run this function fires because the ComRegisterFunction
attribute has been applied. This function creates the BHO registry entries
that enable IE to locate the object.
5. Declares RegisterServer Function that un-registers of the DLL. This
function removes the BHO registry entries.
6. Starts IE in TheaterMode when successfully attached to IE process
In order to test it you will have to:
1. Build in the IE directory
OR
2. Give the assembly strong name (sn.exe) and place in the Global Assembly
Cache
3. Register the DLL for Interop using regasm.exe
4. Copy to IE directory Interop.SHDocVw.dll
The sample does not subscribe to events. You will have to implement this
depending on which events you want to sink
************************************************
Imports System.Diagnostics
Imports System.Reflection
Imports Microsoft.Win32
Imports SHDocVw
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Namespace BasicBHOs
<ComImport(), Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352"), _
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IObjectWithSite
Sub SetSite(<MarshalAs(UnmanagedType.IUnknown)> ByVal pUnkSite As
Object)
Sub GetSite(ByRef riid As Object,
<MarshalAs(UnmanagedType.Interface)>
ByVal ppvSite As Object)
End Interface
<GuidAttribute("F4E44592-01B4-472f-A4C1-CA1BDFE59B50")> Public Class
bhovb
Implements IObjectWithSite
Public m_IE As SHDocVw.InternetExplorer
Sub SetSite(<MarshalAs(UnmanagedType.IUnknown)> ByVal pUnkSite As
Object)
Implements IObjectWithSite.SetSite
Try
m_IE = CType(pUnkSite, InternetExplorer)
'Me.SubscribeToEvents()
Me.Initilize()
Catch
Dim e As Exception
Throw e
End Try
End Sub
Sub GetSite(ByRef riid As Object,
<MarshalAs(UnmanagedType.Interface)>
ByVal ppvSite As Object) Implements IObjectWithSite.GetSite
If m_IE Is Nothing Then
ppvSite = m_IE
Else
ppvSite = Nothing
End If
End Sub
<ComRegisterFunction()> Private Shared Sub RegisterServer(ByVal t
As
Type)
Try
Dim regPrefix As String =
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects\"
Dim guid As Guid = t.GUID
Dim key As RegistryKey = Registry.LocalMachine
Dim keyname As String = regPrefix & "{" & guid.ToString() &
"} "
key.CreateSubKey(keyname)
Catch
Dim e As Exception
End Try
End Sub
<ComUnregisterFunction()> Private Shared Sub UnRegisterServer(ByVal
t As
Type)
Try
Dim regPrefix As String =
"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects\"
Dim guid As Guid = t.GUID
Dim key As RegistryKey = Registry.LocalMachine
Dim keyname As String = regPrefix & "{" & guid.ToString() &
"} "
key.DeleteSubKey(keyname)
Catch
Dim e As Exception
End Try
End Sub
Public Sub Initilize()
m_IE.TheaterMode = True
End Sub
End Class
End Namespace
Thanks.
Best regards,
Yanhong Huang
Microsoft Online Partner Support
Get Secure! ¨C
www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.