VC++资源编译器 (RC) 选项 /n ...?

发布于 2024-12-09 15:42:45 字数 340 浏览 0 评论 0原文

我刚刚阅读了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

欢你一世 2024-12-16 15:42:45

STRINGTABLE 中的字符串通常不以零终止符结尾,而是 STRINGTABLE 的格式指定每个字符串前面带有字符串长度。通常,LoadString() 会将字符串资源复制到应用程序提供的缓冲区中并附加零终止符。在这种情况下,您实际上不需要选项 /n

但是,当您指定 0 时,可以使用 LoadString() (或更准确地说 LoadStringW(),因为 ANSI 变体无法做到这一点)来检索原始字符串资源。 code> 作为缓冲区大小:
<代码>

WCHAR* str;
int str_len;
str_len = LoadStringW(hInstance, ID_STRING, (LPWSTR) &str, 0);

在这种情况下,它只是将原始字符串资源的地址存储到映射到进程内存的 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 exactly LoadStringW() as ANSI variant cannot do that) can be used to retrieve the raw string resource when you specify 0 as the buffer size:

WCHAR* str;
int str_len;
str_len = LoadStringW(hInstance, ID_STRING, (LPWSTR) &str, 0);

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 the LoadLibrary() 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 of LoadLibrary()).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文