[译]带有源代码的命令行工具,可将本机资源添加到任何可执行文件中
By robot-v1.0
本文链接 https://www.kyfws.com/applications/command-line-tool-with-source-code-to-add-native-r-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 5 分钟阅读 - 2201 个词 阅读量 0[译]带有源代码的命令行工具,可将本机资源添加到任何可执行文件中
原文地址:https://www.codeproject.com/Articles/20644/Command-line-tool-with-source-code-to-add-native-r
原文作者:kamnas
译文由本站 robot-v1.0 翻译
前言
A command line tool with source code to add any native Win32 resource (HTML, Icons, BMPs, etc.) to an executable.
一个带有源代码的命令行工具,用于将任何本地Win32资源(HTML,图标,BMP等)添加到可执行文件中.
介绍(Introduction)
此命令行工具将任何文件作为资源添加到您指定的另一个可执行文件.该工具接受诸如文件或目录之类的参数,并带有要添加为资源的文件,以及每个资源的类型和名称.提供了完整的源代码.(This command line tool adds any file as a resource to another executable you specify. The tool accepts arguments like a file or directory with files to be added as a resource, with the type and name for each of the resource. The complete source code is provided.)
背景(Background)
该工具对于使用托管技术(如.NET)生成的可执行文件很有帮助,这些资源未本地嵌入.在某些情况下,您确实希望托管的应用程序具有本机资源.(This tool can be helpful for executables produced with managed technologies like .NET, where the resource files are not natively embedded. There are some situations when you do want that your managed application have native resources.)
例如,如果您想使用(For example, if you wish to use the)资源://(res://)从托管可执行文件(程序集)加载HTML文件的协议.您可以创建构建后步骤,然后运行此工具以将本机资源添加到托管应用程序.(protocol to load an HTML file from your managed executable (assembly). You can create a post build stepn and run this tool to add the native resources to the managed application.)
使用工具(Using the tool)
命令行语法:(Command line syntax:)
AddResource.exe ExePath ResFile [ResName] [ResType]
参数说明:(Arguments description:)
- ExePath(ExePath)-向其添加资源的可执行文件的路径.(- path of the executable file to add resources to.)
- 档案(ResFile)-要添加为资源的文件路径或文件目录.(- path of the file or directory of files to be added as a resource(s).)
- 姓名(ResName)-(可选)资源名称;如果省略,则应用程序将使用文件名作为资源名称.如果(- (optional) name of the resource; if omitted, the application will use the filename as the resource name. If)档案(ResFile)表示目录,然后(denotes a directory, then)姓名(ResName)被忽略.(is ignored.)
- ResType(ResType)-(可选)资源类型;如果省略,则应用程序将尝试使用基于ResFile文件扩展名的默认资源类型之一.例如,(- (optional) type of the resource; if omitted, the application will try to use one of the default resource types based on the ResFile file extension. For example, an)**‘index.html(‘index.html)**的文件将使用(’ file will use the)
RT_HTML
资源类型.(resource type.) 请注意,如果(Note that if)姓名(ResName)要么(or)ResType(ResType)指一个(refers to a)资源ID(resource ID)(满足IS_INTRESOURCE(x)宏),它将像((satisfies the IS_INTRESOURCE(x) macro), it will be used like a)**资源ID(resource ID)**不作为(not as a)资源字符串(resource string).例如,如果(出于一个奇怪的原因)您想要的资源类型为23,(. For example, if (for a strange reason) you want to have a resource type of 23 as)串(string),您将无法做到这一点.如果您不了解此注释对资源名(字符串)和资源名(整数)之间的区别的理解,请忽略它,因为99.99%的用户将不需要它.(, you won’t be able to do that. If you don’t know understand what this note says about the difference between a resource name as string and resource name as integer, ignore it, as 99.99% you won’t need it.)
例(Example)
AddResource.exe myManagedApp.exe Help.htm help.htm 23
这等效于省略资源类型:(It is equivalent to omitting the resource type:)
AddResource.exe myManagedApp.exe Help.htm help.htm
因为的价值(because the value of) RT_HTML
是(is)23.(23.)
如果您的目录中包含要添加为资源的文件,请传递目录路径.(If you have a directory with files you want to add as a resource, you pass the directory path.)
AddResource.exe myManagedApp.exe U:\Projects\myManagedApp/Resources
目录中的每个文件都将使用资源名称,文件名添加为资源,并且资源类型将基于文件类型来确定.(Each file from the directory will be added as a resource using the resource name, the filename, and the resource type will be determined based on the file type.)
该应用程序自动将HTML文件映射到(The application automatically maps HTML files to) RT_HTML
,将BMP文件(, BMP files to) RT_BITMAP
和ICO文件(, and ICO files to) RT_ICON
.文件类型由其扩展名确定.其他任何类型的文件都会自动添加到(. The file type is determined by its extension. Any other type of file is automatically added to the) RT_HTML
类型.(type.)
例如:(For example:)
假设您在目录中具有以下文件:(Let’s say you have in a directory the following files:)索引(Index.htm),(,)图片1.jpg(Image1.jpg),(,)Image2.bmp(Image2.bmp).(.)**索引(Index.htm)**映射到(is mapped to) RT_HTM
,(,)**图片1.jpg(Image1.jpg)**至(to) RT_HTML
和(, and)**Image2.bmp(Image2.bmp)**至(to) RT_BITMAP
.(.)
兴趣点(Points of interest)
的(The)添加资源(AddResource)该工具使用Win32文件映射API在其地址空间中映射源资源文件,并调用Win32 API资源函数以更新目标可执行文件.它使用互斥锁在同一可执行文件上同步更新.查看源代码以获取更多信息.(tool maps the source resource file in its address space using the Win32 file mapping API, and calls Win32 API resource functions to update the target executable. It uses a mutex to synchronize the update on the same executable. Check the source code for more.)
请随时添加任何评论\建议,我们将竭诚为您服务.(Please feel free to add any comments \ suggestions, I’ll be happy to help.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
VC7.0 VC7.1 VC6 WinXP Win2003 Win2K VS2005 Visual-Studio VS.NET2003 Dev 新闻 翻译