best practice is to write a BHO which will load your BandObject.
A BHO has to implement IObjectWithSite
--- IObjectWithSite.cs ---
using System;
using System.Runtime.InteropServices;
namespace <YOUR_NAMESPACE_HERE>
{
[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352")]
public interface IObjectWithSite
{
[PreserveSig]int SetSite([MarshalAs(UnmanagedType.IUnknown)] object site);
[PreserveSig]int GetSite(ref Guid guid, out IntPtr ppvSite);
}
}
--- BHO.cs ---
using
System;using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using SHDocVw;
namespace <YOUR_NAMESPACE_HERE>
{ [ComVisible(true)]
[Guid("<YOUR_GUID_HERE>")]
[ClassInterface(ClassInterfaceType.None)] public class BHO : IObjectWithSite
{
private InternetExplorer explorer;
#region ComRegisterFunction
public static string BHOKEYNAME = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects";
[
ComRegisterFunction]public static void RegisterBHO(Type t)
{
RegistryKey key = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true);
if (key == null)
{
key = Registry.LocalMachine.CreateSubKey(BHOKEYNAME);
} string guidString = t.GUID.ToString("B");
RegistryKey bhoKey = key.OpenSubKey(guidString, true); if (bhoKey == null)
{
bhoKey = key.CreateSubKey(guidString);
} // NoExplorer:dword = 1 prevents the BHO to be loaded by Explorer
string _name = "NoExplorer";
object _value = (object)1;
bhoKey.SetValue(_name, _value);
key.Close();
bhoKey.Close();
}
[
ComUnregisterFunction]public static void UnregisterBHO(Type t)
{
RegistryKey key = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true);
string guidString = t.GUID.ToString("B"); if (key != null)
{
key.DeleteSubKey(guidString, false);
}
}
#endregion
#region
IObjectWithSite Memberspublic int SetSite(object site)
{
if (site != null)
{
explorer = (InternetExplorer)site;
ShowBrowserBar(true);
}
return 0;
} public int GetSite(ref Guid guid, out IntPtr ppvSite)
{
IntPtr punk = Marshal.GetIUnknownForObject(explorer);
int hr = Marshal.QueryInterface(punk, ref guid, out ppvSite);
Marshal.Release(punk);
return hr;
}
#endregion
#region
Private Functions private void ShowBrowserBar(bool bShow){
object pvaClsid = (object)(new Guid("GUID_OF_YOUR_BANDOBJECT_HERE").ToString("B"));
object pvarShow = (object)bShow;
object pvarSize = null;
if (bShow) /* hide Browser bar before showing to prevent erroneous behavior of IE*/
{
object pvarShowFalse = (object)false;
explorer.ShowBrowserBar(ref pvaClsid, ref pvarShowFalse, ref pvarSize);
}
explorer.ShowBrowserBar(
ref pvaClsid, ref pvarShow, ref pvarSize);}
#endregion
}
}
'IT-개발,DB' 카테고리의 다른 글
[개발] VC++ IWebBrowser2 IHTMLDocument2 상호변환 (0) | 2010.09.14 |
---|---|
[개발/웹] VC++ ATL을 이용한 Scriptable ActiveX 제작 (0) | 2010.09.13 |
[VC++] 문자열변환 CString LPSTR WCHAR* LPCWSTR (0) | 2010.09.10 |
c# delay 함수 / C# Delay function (0) | 2010.09.10 |
[VC#] C++로 만든 DLL 을 C#에서 사용하기 (0) | 2010.09.10 |
댓글