Delphi

Adding HTML Resources and Images to Dll and Exe that IE can reference

If you want to add html pages or images to your dll
or exe in delphi it is a simple matter of adding the pages as resources. This article
covers adding html and image files to the resource, and how to pass infromation
to the html file to make it a bit more dynamic.

Stage 1) How do we add an image or
html document to a exe or dll.

Create a file in the project directory (e.g. called MyProjectRes.rc). The easiest
application to create this in is notepad, you can create it in delphi, but make
sure the extension is .rc.

Choose Project->Add To Project… then change the Files of Type to Resource File
(*.rc), select the .rc file (e.g. MyProjectRes.rc) and choose Open.

In the RC file we can add lines that define the resource to include. These are of
the format :

[Resource Name][Space or Tab][Resource Type][Space or Tab][Filename of resource]

e.g 
PICTURE1 GIF ".ImagesMyImage.gif"

Delphi should have automatically added a line into the project source (e.g.
{$R 'HTMLResources.res' 'HTMLResources.rc'}) so when the project is built it will
automatically compile the Resource script file (.rc) into a resource *.res.

You can now access these resources in code by using a TResourceStream or TBitmap.LoadFromResource
for example.

Stage 2) Specifying HTML resources and images.

If we used the above example of a resource (PICTURE1 GIF ".ImagesMyImage.gif")
then we can reference the resource via Internet Explorer as the URL

res://c:program%20filesmydll.dll/GIF/PICTURE1

The Url starts with the res:// followed by the path to the dll or exe with the resource
(using backslash not forward slash) then /[Resource Type]/[Resource Name]

If you wish to add a resource that can be accessed directly with out the need to
specify the Resource Type portion of the URL then you can add it as follows :

Name 2110 DISCARDABLE "path to file"

The type 2110 allows the resource to be referenced at the root of the url e.g.

res://c:program%20filesmydll.dll/Name

The discardable option means that if windows needs memory then this resource can
be release and only reloaded when needed.


Stage 3) Creating a dynamic HTML resource

It is possible, to use the querystring part of a URL to send parameters or information
to the HTML resource. To do this we use a bit of java script to extract the querystring
from the URL.

e.g. I created this Javascript function to extract text between # and ## 

function Homepage(){
  DocURL=document.location.href;
  BeginInfo=DocURL.indexOf("#")+1;
  EndInfo=DocURL.indexOf("##");
  urlresult=DocURL.substring(BeginInfo,EndInfo);
  document.write('' + unescape(urlresult) + "");
}

This is simply called a the the appropriate point to insert the querystring text
there.

Homepage();

I can the use a resource like res://c:program%20filesmydll.dll/error#My Message
to display##

Note in the JavaScript function the use of unesacpe to remove the %20 that IE puts
in instead of the spaces.

Images and other resources can be referenced as relative paths from the dll resource.

e.g

<img xsrc="GIF/ImageUnderGIFType" width="50" height="45"

or

<img xsrc="GIFAtRoot" width="50" height="45">