1

I am running Vista Home Premium with C# Express 2010

I am having trouble loading a WIN32 resource image from my C# BHO into the DOM when IE loads a page. I would appreciate some help in identifying where the problem and how to fix it.

I am starting with the code found here: (Sorry about the rest of the links. I just started here and don't have enough reputation to post multiple links yet. I put them in code blocks so that you can see where I got the info from)

http://www.codeproject.com/Articles/19971/How-to-attach-to-Browser-Helper-Object-BHO-with-C

I can get the code to install, and IE to execute javascript on pages as they load. I have an image that I want to add to the DOM. currently the code I am using to try and and add the image is:

string img = "<img id=\"BHOimg\" src=\"res://BHOHelloWorld.dll/#2/LOGO.bmp\">";
document.body.insertAdjacentHTML("afterBegin", img);

where BHOHelloWorld.dll is the BHO this code is from. With this approach the image node is added to the DOM, but the image is a red X. I have looked in the BHOHelloWorld.dll once it is compiled using PE Explorer and can see the logo.bmp resource. The fact that I can see the image leads me to believe that the src attribute is wrong. it is worth noting that when I use PE Explorer the image name is LOGO.BMP instead of LOGO.BMP

BHOHelloWorld was compiled utilizing the following these steps:

starting here:

http://stackoverflow.com/questions/9156177/how-to-embed-an-image-on-a-web-page-from-a-bho

I have created an RC file (nativeresources.rc) with the following content:

logo.bmp bitmap "logo.bmp"

I then added

"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\rc.exe" /r "../../nativeresources.rc"

to my prebuild events for my project.

I have also added

<Win32Resource>nativeresources.res</Win32Resource>

to my csproj file on the advice of this link

http://www.calvert.ch/maurice/2009/08/27/displaying-images-using-the-res-protocol-from-a-ie-bho/

I am compiling my BHOHelloWorld project using csc.exe on the command line, because MS told me that I have to use the /win32res flag and that the VS IDE didn't support it.

http://msdn.microsoft.com/en-US/library/8f2f5x2e(v=vs.80).aspx

To get the right csc.exe command I changed C# Express output to be verbose and compiled. I then just copied it the csc command from the output window to the commandline and added

/win32res:nativeresources.res

Everything seems to compile and embed fine in that rc.exe creates a .res file without throwing any errors. The res file is only slightly bigger than the image file, and once I have built the BHOHelloWorld.dll file, I can open it with PE Explorer and can see the image in question albeit with a slightly different name of LOGO.BMP. I am not sure if this is an artifact of PE Explorer, or a problem with the way I compiled / embedded. In any event I have tried replacing the image src attribute to reflect the different name with no luck. I have now spent a couple of days on this and feel stuck. any help would be appreciated.

I have also looked at these with no real luck:

http://stackoverflow.com/questions/20266564/how-to-add-image-tag-in-bho-using-c
http://stackoverflow.com/questions/12962563/bho-accessing-resource-in-managed-dll
http://stackoverflow.com/questions/8739767/ie-image-is-displayed-in-localhost-but-not-onlinebho
Semicolons and Duct Tape
  • 2,927
  • 4
  • 20
  • 35

0 Answers0