我已经好几天了 . 我创建了一个IE加载项,可以在32位IE上注册并运行良好 . 当我试图让它在64位Windows 7上运行时,我的问题就出现了 . 正如我发现的那样,64上的IE运行32和64.因此尝试通过使用32-注册32位dll来运行我的附加组件bit regasm让它运转起来 . 但是,使用64位regasm注册64位dll不起作用 . 如果我在增强保护模式下运行IE,则加载项有效 .

我试图让IE运行我的64位加载项而没有增强保护模式,因为其他附加组件只需要在32位EI上运行,因此在使用增强模式时被禁用/不兼容 . 我还需要能够以64位而不是32位运行我的DLL,因为我正在使用我的dll与必须在64位的驱动程序/固件进行通信,因此它们可以在Windows上运行 .

没有增强模式:

我尝试用regasm 64注册64位BHO Dll -----没有运行我的附加组件但我可以在管理附加组件中看到它我尝试用regasm 64和32注册任何CPU BHO Dll ---- - 可以看到添加并运行它但在尝试调用硬件时它失败了,因为硬件需要从64位调用 . (缺少依赖...)

这是我的代码减去扩展名的副本

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SHDocVw;
using mshtml;
using System.IO;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using EyeBank_API;
using System.Runtime.InteropServices.Expando;
using System.Reflection;
using System.Windows.Forms;

namespace IEPlugin
{
    [
    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);
    }


    [
        ComVisible(true),
        Guid("2159CB25-EF9A-54C1-B43C-E30D1A4A8277"),
        ClassInterface(ClassInterfaceType.None), ProgId("MyExtension"),
        ComDefaultInterface(typeof(IExtension))

    ]
    public class BHO : IObjectWithSite, IExtension
    {
        private SHDocVw.WebBrowser webBrowser;

        public int SetSite(object site)
        {
            if (site != null)
            {
                webBrowser = (SHDocVw.WebBrowser)site;
                webBrowser.DocumentComplete +=
                  new DWebBrowserEvents2_DocumentCompleteEventHandler(
                  this.OnDocumentComplete);
            }
            else
            {
                webBrowser.DocumentComplete -=
                  new DWebBrowserEvents2_DocumentCompleteEventHandler(
                  this.OnDocumentComplete);
                webBrowser = null;
            }

            return 0;

        }

        public int GetSite(ref Guid guid, out IntPtr ppvSite)
        {
            IntPtr punk = Marshal.GetIUnknownForObject(webBrowser);
            int hr = Marshal.QueryInterface(punk, ref guid, out ppvSite);
            Marshal.Release(punk);
            return hr;
        }

        public void OnDocumentComplete(object pDisp, ref object URL)
        {
            try
            {
                dynamic window = webBrowser.Document.parentWindow;
                IExpando windowEx = (IExpando)window;
                windowEx.AddProperty("MyExtension");
                window.myExtension = this;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }


        public string CallHardware()
        {
            bool capture = true;
            string result = Library.Call_Hardware_Connect(capture);
            return result;
        }


        public const string BHO_REGISTRY_KEY_NAME =
   "Software\\Microsoft\\Windows\\" +
   "CurrentVersion\\Explorer\\Browser Helper Objects";

        [ComRegisterFunction]
        public static void RegisterBHO(Type type)
        {
            RegistryKey registryKey =
              Registry.LocalMachine.OpenSubKey(BHO_REGISTRY_KEY_NAME, true);

            if (registryKey == null)
                registryKey = Registry.LocalMachine.CreateSubKey(
                                        BHO_REGISTRY_KEY_NAME);

            string guid = type.GUID.ToString("B");
            RegistryKey ourKey = registryKey.OpenSubKey(guid);

            if (ourKey == null)
            {
                ourKey = registryKey.CreateSubKey(guid);
            }

            ourKey.SetValue("NoExplorer", 1,RegistryValueKind.DWord);

            registryKey.Close();
            ourKey.Close();
        }

        [ComUnregisterFunction]
        public static void UnregisterBHO(Type type)
        {
            RegistryKey registryKey =
              Registry.LocalMachine.OpenSubKey(BHO_REGISTRY_KEY_NAME, true);
            string guid = type.GUID.ToString("B");

            if (registryKey != null)
                registryKey.DeleteSubKey(guid, false);
        }

    }

    [ComVisible(true)]
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    [Guid("B9BBD37E-510C-4e7c-9ADD-222B72752E0D")]
    public interface IExtension
    {
        [DispId(1)]
        string CallHardware();
    }
}

管理让它在两者上工作 . 但是,一些运行Java Applet的网站无法调用我的扩展程序 . 它适用于每个站点,我可以正常调用该函数,但是,当我尝试从Java applet站点运行它时它不起作用 . 我尝试了一切 .