Use of RES protocol in. net

Source: Internet
Author: User
Previously, I wrote about embedded web pages in winform (DHTML code interacts with winfrom applications). In fact, DHTML web applications are converted into common winform applications. (DHTML, HTML, and other server-side web applications are embedded ). In this way, the winform application needs to maintain some DHTML or HTML files.

Thoughts: Can we think about how to separate these HTML (DHTML) separately. According to the compilation idea, can we compile these HTML (DHTML), including some resource files (images, scripts, and styles) into a common DLL file.
Research: The answer is yes: in this way, we need to use the res protocol to extract resources from the program module.
Effect: Generate a program module (Dynamic Connection Library) file from the HTML (DHTML) file to be loaded in winform. We can use the res protocol to access and extract resources from the program module.
Below is the reprinted content: if you are not clear about the res protocol, you will suddenly realize it after reading it.
Reprinted: http://baike.baidu.com/view/1508651.html (the following red representation was corrected)

What is the res protocol?

When an incorrect address is entered in the address bar of IE, the error page is displayed. On the error page, right-click and click Properties. view the page source and you will find a connection similar to this: Res: // C:/Windows/system32/shdoclc. the above dll/dnserror.htm address is an example of the res protocol. "Res: //" is a predefined protocol of IE 4.0. It can be used to extract resources, slices, sounds, strings, and so on from program modules. The program module here generally refers to files in Win32 PE format, such as normal EXE and DLL. Try entering the following content in the IE Address Bar: Res: // shell32.dll/2/javasres: // shell32.dll/2/147 note: the first one is a representation of Windows XP Professional. The second is the representation of Windows XP Home Edition.

1. In the description of the res protocol syntax on msdn, it is pointed out that if the Stype and Sid in the path are numbers, the '#' character must be prefixed to ensure correctness, however, when I tested ie6.0 with SP2, I found that if the '#' character is added before stype and Sid, an error may occur. On the contrary, there is no problem when you do not add it. It may be that Microsoft corrected res usage in SP2, or msdn encountered an error (this may not seem very likely ). However, our application can use strings instead of numbers, so even the correction of SP2 does not affect compatibility.
2. Run "res: // D: \ test \ mydll. dll/2/234 ", for example, D: \ test \ mydll. DLL part, that is, the sfile part must be a path in Windows format. For example, you cannot write it as D:/test/mydll. DLL format. The stype and Sid must be in the '/' format. Otherwise, problems may occur. There is another small problem. How do I know the resources in a DLL or EXE? The well-known resource extraction tool exists. Open an EXE or DLL with excoder, and you can easily browse, modify, and extract its resources. Even for some shell programs, excoder can be used as a simple software. Up to now, there is no problem with the application of the res protocol,
3. The next question we discuss is to create a resource DLL. Take vc6.0 as an example:

3.1 create a project and select Win32 dynamic-Link Library as the type. Enter the project name test. Click OK
3.2. In the DLL type, select an empty DLL project. Click Finish.
3.3 at this time, the project was empty and there was nothing. We need to add a resource script for it. Click file-> New, select resource script on the files tab, enter the file name test. RC, and click OK. In this way, the project contains a resource script file. Open File View and you can see it in source files. Select it, right-click it, and select open. The resource view tab appears in work space. This facilitates subsequent resource addition operations.
3.4. Click project-> Settings ..., Select Win32 release for setting, click the link tab on the right, and add the/noentry parameter in the bottom project options. Remember to open the parameter with spaces before or after. This parameter is the basis for successful resource DLL connection.
3.5. Click build-> batch build ..., Select only Win32 release and click build. Generate the resource DLL of the release version. Of course, the DLL created in the above steps is just an empty shell and contains no resources. The following describes how to add resources to the DLL.
3.6 In resource view, right-click and select insert. In the dialog box that appears, select new or import. Taking import as an example, if you want to add resources that are pre-defined, such as bitmap, you can directly select the file to be introduced and then import. For a custom type, enter the type name (stype in future res address ).
3.7 after a resource is introduced, VC automatically defines an ID for the resource, which is generally in the form of a number. "Accept". Note that the "" here cannot be omitted; otherwise, the VC will not accept the input ('. or set a number as the ID (for example, set it to test, it is still a number ).
What if the resource to be added contains the directory hierarchy? For example, to upload a page named test.htm, a link is directed to miki.jpg under the imagesfile, that is, . How can I add it? First of all, they must all be placed under the same type of resources, such as user-defined resource test. Then add a directory under test? I haven't added it for a long time (if a super high hand knows how to do it, please share it with me ). Therefore, a stupid method is used: This directory is displayed when the resource ID is set, that is, the ID of test.htmis set to test.htm, And the ID of miki.jpg is set to "images/miki.jpg ". The resource DLL test "res: // test. dll/test/test.htm" is created successfully. At the same time, to ensure that resources are released at the directory level, rather than by writing "images/miki.jpg.pdf as a name (because test.htm can still properly connect to images at this time ).
A new test was conducted:
Change the connection in 110000test.htm to .
2. Modify test.htm's ID to "test/test.htm.pdf, and miki.jpg's ID to" images/miki.jpg ".
3. After the DLL is generated, test "res: // test. dll/test/test.htm. This method is valid.

Best regards,
Charles Chen

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.