How to embed an image on a web page from a BHO?

旧城冷巷雨未停 提交于 2020-01-13 13:50:44

问题


I have a BHO library mybho.dll written in C#. I have embedded a Resource file "image.png". I'd like to show this image on some pages. According to what I read, it should look like this:

<img src="res://mybho.dll/image.png">

But Internet Explorer does not find the image. I've tried this one without success:

<img src="res://mybho.dll/#2/image.png">

What is the right way to do it?


回答1:


You are confusing Win32 resources and .NET assembly resources. the 'res:' protocol handler returns a Win32 resource from a DLL. .NET resources are NOT Win32 resources, and as such IE (Actually urlmon.dll, where res: is implemented) cannot find your image.

You have two options:

  1. The easiest way would probably be to create a Win32 resource (*.res file) and embed it into the managed assembly. First, create a *.RC file, which points to your image. I'm not sure, but I think you'll have to convert your PNG to BMP format first. Then, compile the RC file into a binary resource (with RC - the Resource Compiler). Finally, as you build your managed assembly, use the /win32res switch to add the Win32 resource.

  2. You can also implement a Asynchronous Pluggable Protocol handler. Say you want to implement a new protocol scheme: julien://image.png'. Register it at HKCR\PROTOCOLS\Handler\julien, and implement IInternetProtocol (and few other protocols). This is NOT a very easy task (did it once - there are many opportunities to make mistakes).



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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!