Reputation: 625
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.
Upvotes: 2
Views: 579
Reputation: 2349
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()
).
Upvotes: 2