When an incorrect address is entered in the address bar of IE, IE will display an error page. On the error page, right-click and then click Properties. If you look at the source of the page, you will see that it is a link like this:
res: // C: /WINDOWS/system32/shdoclc.dll/dnserror.htm
The above address is an example of the res protocol.
The "RES: //" protocol is a predefined protocol in IE 4.0. It can be used to extract resources in program modules, such as pictures, sounds, strings, and so on. The program module here generally refers to files that conform to the WIN32 PE format, such as ordinary EXE, DLL, and so on.
Try entering the following in the IE address bar:
res: //shell32.dll/2/131
res: //shell32.dll/2/147
Note:
The first is a presentation pattern for windows xp professional.
The second is a representation of windows xp home edition.
Let's see what MSDN says about the res protocol:
res Protocol
Specify a resource that will be obtained from a module.
Syntax
res: // sFile [/ sType] / sID
Tokens
sFile
Path and file name of the module that contains the resource.
sType
Optional. String or numerical resource type. This can be either a custom resource or one of the RT_ predefined resource types described in the FindResource function reference. If a numerical resource type is specified, the actual number of the identifier, not the identifier name, must follow a # character. See the example for more information. If this parameter is not specified, the default resource type is RT_HTML.
sID
String or numerical identifier of the resource. If a numerical identifier is specified, the actual number of the identifier, not the identifier itself, must follow a # character. See the example for more information.
Remarks
Available as of Microsoft® Internet Explorer 4.0 or later.
Remember, URLs require that special characters such as '#' be escaped. Use '% 23' to escape the '#' character.
Note Internet Explorer 6 Service Pack 1 (SP1) no longer allows browsing a local machine from the Internet zone. For instance, if an Internet site contains a link to a local file, Internet Explorer 6 SP1 displays a blank page when a user clicks on the link. Previous versions of Internet Explorer followed the link to the local file.
Example
This example shows the correct and incorrect ways to format the numerical identifier for the resource type.
#define MYBITMAP 234
// This is correct.
"res: //mydll.dll/#2/#234"
// This is not correct.
"res: //mydll.dll/#2/MYBITMAP"
You can see the comprehensive information of the res protocol above. Includes syntax, applications, examples, and related descriptions.
But here are two minor issues:
1. The description of the syntax of the res protocol on MSDN indicates that if the sType and sId in the path are numbers, they must be preceded by a '#' character to ensure the correctness. However, I tested in IE6.0 with SP2 I found that if you put a '#' character in front of sType and sID, an error will occur; on the contrary, there will be no problem when you don't add it.
Conjecture may be that Microsoft has corrected the use of res in SP2, or it is a mistake in MSDN (this possibility does not seem very high). However, our application can completely replace strings with strings, so even corrections in SP2 will not affect compatibility.
2. Take "res: // d: /test/mydll.dll/2/234" as an example. The d: /test/mydll.dll part, that is, the sFile part must be a path in the windows format. /test/mydll.dll.
The following sType and sID parts must be in the form of '/', otherwise problems will occur.
There is also a small question, how to know what resources are in a dll or exe?
This of course uses eXeScope, a well-known resource extraction tool. Using eXeScope to open an exe or dll, you can easily browse, modify, and extract its resources. Even some shelled programs, so eXeScope can also be used as a simple software localization.
Until now, there is no problem with the application of the res protocol. The next issue we discuss is creating a resource DLL.
Take VC6 as an example,
1. Create a new project and select Win32 Dynamic-Link Library. Enter the project name Test. Click OK
2. For DLL type, select An Empty DLL Project. Then click Finish.
3. At this time, the project is empty and there is nothing. We need to add a resource script for it. Click File-> New,
Select Resource Script in the Files tab, enter the file name test.rc, and click OK.
In this way, a resource script file is included in the project. Open File View, you can see it in Source Files. Select it, right-click, and select Open. The Resource View tab appears in Work Space. Convenient for adding resources in the future.
4. Click Project-> settings…, then select Setting For Win32 Release, click the link tab on the right, and add the / NOENTRY parameter in the bottom of Project Options. Remember to use a space between the previous and subsequent parameters. This parameter is the basis for a successful resource DLL connection.
5. Click Build-> Batch Build ..., select only Win32 Release, and then click Build. Generate a Release version of the resource DLL.
Of course, the DLL created in the above steps is just an empty shell without resources. The following section discusses adding resources to the DLL.
In the Resource View, right-click and select Insert. A pop-up dialog box appears. Select either new or import. Take import as an example. If the resource you want to add is predefined, such as bitmap, you can directly select the file to be imported and then import. If it is a custom type, you must fill in the name of the type (sType in future res address). Generally after the introduction of resources, VC automatically defines an ID for the resource, which is usually in the form of a number. Of course, we can also customize the ID. For example, if we want to define the ID as Test.jpg for a JPG image, open the property dialog box of the resource, and then fill in the "Test.jpg" in the ID column. Note that "" cannot be omitted Otherwise, VC will not accept the input (the presence of '.'), Or still set a number for him as the ID (if set to TEST, it is still a number).
Then, what if the resource to be added contains a directory hierarchy?
For example, to add a page test.htm, a link in the page points to miki.jpg in the images folder, that is: <img src = ”images / miki.jpg”>. How to add it?
The first thing to be sure of is that they must all be placed under the same type of resource, such as the custom resource TEST. Then add a directory under TEST? I tried it for a long time and did not add it (if a Super high hand knows how to do it, please share it with me). Therefore, a relatively stupid method is adopted: when setting the resource ID, the directory hierarchy is reflected, that is, the ID of test.htm is set to "test.htm" and the ID of miki.jpg is set to "images / miki. jpg ". Then make the resource DLL test "res: //test.dll/TEST/test.htm" successful. At the same time, in order to ensure that the resources are released according to the directory hierarchy, not because "images / miki.jpg" is released as a name (because test.htm can still correctly connect the pictures at this time), a new test is performed:
1. The link in test.htm is changed to <img src = ”../ images / miki.jpg”>.
2. Modify the ID of test.htm to "test / test.htm". At this time, the ID of miki.jpg is "images / miki.jpg".
After the DLL was generated, the test "res: //test.dll/TEST/test/test.htm" was successful.
Prove this method is effective.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.