Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
130 views
in Technique[技术] by (71.8m points)

c# - Cannot get BHO working in 64 bit

I'm working on IE11 Browser Helper Object. I got it working when I build it in x86. The problem is, I want to use the project on x64 the BHO extension isn't working when it's built on x64.

The extension shows up in the Internet Explorer add-ons screen, but the javascript popup is not showing up.

The DLL is registered using the x64 version of regasm via the Visual Studio command prompt as administrator, with/without the /codebase and /tlb but without result. The registry key is added successfully in my registry but the BHO is simply not working in IE. I've also tried placing the files in a subfolder of Program Files, but it simply is not working.

When I run my IE in Enhanced Protected Mode the add-on manager shows that my BHO is incompatible, but without EPM the IE shows enabled even though it's not working.

I'd like to get the BHO working on x64.

I also tried this 'hello world' BHO project but when I change it to build on x64 in stead of x86 the same problem occurs.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It seems it doesn't work for everyone, so, I'll describe what I did to make it work.

1) download the sample project from here: https://github.com/reinaldo13/ie-bho-extension

2) modify RegisterBHO(...) method in BHO.cs

from:

RegistryKey ourKey = registryKey.OpenSubKey(guid);

to:

  RegistryKey ourKey = registryKey.OpenSubKey(guid, true); //we want to write the registry

3) compile the project for AnyCPU: Project properties, select AnyCPU for the platform target.

4) create a .bat like this, adapt yo your path, and copy that aside your outputs dll:

 "c:WindowsMicrosoft.NETFrameworkv4.0.30319RegAsm.exe" ieextension.dll /codebase
 "c:WindowsMicrosoft.NETFramework64v4.0.30319RegAsm.exe" ieextension.dll /codebase   

This will register the dll for x86 and x64. This is mandatory to have both version registered otherwise IE won't like it (it will complain the extension is 'incompatible') because it won't be able to start it depending on your IE settings. Note I suppose you can have two different files for each version but .NET's AnyCPU doesn't need that.

5) run that .bat as admin, here is the output when I do this:

"c:WindowsMicrosoft.NETFrameworkv4.0.30319RegAsm.exe" ieextension.dll /codebase
Microsoft .NET Framework Assembly Registration Utility version 4.7.2046.0
for Microsoft .NET Framework version 4.7.2046.0
Copyright (C) Microsoft Corporation.  All rights reserved.

RegAsm : warning RA0000 : Registering an unsigned assembly with /codebase can cause your assembly to interfere with other applications that may be installed on the same computer. The /codebase switch is intended to be used only with signed assemblies. Please give your assembly a strong name and re-register it.
Types registered successfully
"c:WindowsMicrosoft.NETFramework64v4.0.30319RegAsm.exe" ieextension.dll /codebase
Microsoft .NET Framework Assembly Registration Utility version 4.7.2046.0
for Microsoft .NET Framework version 4.7.2046.0
Copyright (C) Microsoft Corporation.  All rights reserved.

RegAsm : warning RA0000 : Registering an unsigned assembly with /codebase can cause your assembly to interfere with other applications that may be installed on the same computer. The /codebase switch is intended to be used only with signed assemblies. Please give your assembly a strong name and re-register it.
Types registered successfully

6) run iexplore.exe. It may work depending on your settings (displays a "HOLA!!!" messagebox), but anyway, go to menu Tools / Internet Options / Programs / Manage add-ons, this is what I see:

enter image description here

If the extension is disabled, you should be able to enable it (and restart).

If it doesn't work (by default it shouldn't), make sure you've checked "Enable 64-bit processes for Enhanced Protected Mode*" (needs restart). To me the message is wrong, it should just say "Enable 64-bit processes"...

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...