VC++资源编译器 (RC) 选项 /n ...?
我刚刚阅读了 VC++ 2010 (rc.exe) 附带的资源编译器的可用命令行选项的描述,其中一个引起了我的注意:
/n :将 null 附加到字符串表中的所有字符串也许
答案是显而易见的,我只是没有考虑正确的道路,但是这个选项什么时候有用?
首先,根据 MSDN 文档,字符串表中的字符串“只是空终止的 Unicode 或 ASCII 字符串,可以在需要时从可执行文件加载”。其次,LoadString 的文档进一步指出该函数“从与指定模块关联的可执行文件加载字符串资源,将字符串复制到缓冲区中,并附加一个终止空字符”
谢谢。
I was just reading the description of the available command line options for the resource compiler that ships with VC++ 2010 (rc.exe), and one of them caught my attention:
/n : Append null's to all strings in the string tables
Maybe the answer is obvious and I'm just not thinking down the right path, but when would this option be relevant?
First of all according to the MSDN documentation strings in a string table are "simply null-terminated Unicode or ASCII strings that can be loaded when needed from the executable file". Secondly, the documentation for LoadString further states that the function "loads a string resource from the executable file associated with a specified module, copies the string into a buffer, and appends a terminating null character"
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
STRINGTABLE 中的字符串通常不以零终止符结尾,而是 STRINGTABLE 的格式指定每个字符串前面带有字符串长度。通常,
LoadString()
会将字符串资源复制到应用程序提供的缓冲区中并附加零终止符。在这种情况下,您实际上不需要选项/n
。但是,当您指定
0
时,可以使用LoadString()
(或更准确地说LoadStringW()
,因为 ANSI 变体无法做到这一点)来检索原始字符串资源。 code> 作为缓冲区大小:<代码>
在这种情况下,它只是将原始字符串资源的地址存储到映射到进程内存的
str
中,并且不会发生字符串复制。显然,LoadLibrary()
实现根本无法添加终止符,此时资源编译器选项就很方便,因为使用零终止字符串比使用字符串长度(返回值)要容易得多LoadLibrary()
)。The strings in the STRINGTABLE are not usually terminated by zero terminator, instead the format of STRINGTABLE specifies each string is preceded with string length. Normally
LoadString()
copies the string resource into an application-provided buffer and appends the zero-terminator. In that case you actually do not need the option/n
.However
LoadString()
(or more exactlyLoadStringW()
as ANSI variant cannot do that) can be used to retrieve the raw string resource when you specify0
as the buffer size:In this case it just stores the address of the original string resource into the
str
as mapped into process memory and no string copying happens. Obviously theLoadLibrary()
implementation then simply cannot add the terminator and this is when the resource compiler option is handy as work with zero-terminated strings is so much easier then using the string length (the return value ofLoadLibrary()
).