Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

435 lines
21 KiB

  1. This document describes how messages will be input, stored and formatted
  2. by a Win32 application.
  3. 1. Message Input
  4. Messages are input as ASCII text in a text file. The format of this
  5. file supports specifying multiple versions of the same message text,
  6. one for each language supported. It also supports automatic assignment
  7. of code numbers to each message, along with the generation of a C
  8. language include file for use by the application for accessing the
  9. messages using symbolic constants. The purpose of the message text
  10. file is to define all of the messages needed by an application, in a
  11. format that makes it easy to support multiple languages with the same
  12. image file.
  13. Message text files are converted into binary resource files by the
  14. MC program. These binary resource files are then input to the RC
  15. compiler which will put them in the resource table for an
  16. application or DLL.
  17. The format of the message text file (default extension is .mc).
  18. Basic syntax is Keyword=Value, where spaces around the equal sign
  19. are ignored, and the value is delimited by white space from the next
  20. keyword=value pair. Case is ignored when comparing against keyword
  21. names. The value portion can either be a numeric integer constant,
  22. {NUMBER}, using C syntax; a symbol name, {NAME}, that follows the
  23. rules for C identifier names; or a file name that follows the
  24. rules for the FAT file system (8 characters or less, no periods).
  25. Comment lines are allowed in the message text file. The comment
  26. syntax is the same as for WIN.INI, namely a semicolon begins a
  27. comment which is terminated by the end of the line. Comments that
  28. exist by themselves on a line are copied as is to the output .h
  29. file.
  30. The overall structure of a message text file consists of a header
  31. section which contains zero or more of the following keywords:
  32. MessageIdTypedef={NAME}
  33. SeverityNames=({NAME}={NUMBER}:{NAME})
  34. FacilityNames=({NAME}={NUMBER}:{NAME})
  35. LanguageNames=({NAME}={NUMBER}:{FILENAME}[:{CODEPAGE}])
  36. OutputBase={NUMBER}
  37. These keywords have the following meaning:
  38. MessageIdTypedef - gives a symbolic name that is output as the
  39. typedef name for each numeric MessageId value. The default
  40. value for this is NULL, which means there will be no type
  41. cast output when defining symbolic names for a MessageId.
  42. SeverityNames - defines the set of names that are allowed as the
  43. value of the Severity keyword in the message definition.
  44. The set is delimited by left and right parenthesis.
  45. Associated with each severity name is a number that, when
  46. shifted left by 30, gives the bit pattern to logically OR
  47. with the Facility value and MessageId to come up with the
  48. full 32-bit message code. The default value of this keyword
  49. is:
  50. SeverityNames=(Success=0x0
  51. Informational=0x1
  52. Warning=0x2
  53. Error=0x3
  54. )
  55. Severity values occupy the high two bits of a 32-bit message
  56. code. Any severity value that does not fit in two bits is
  57. an error. The severity codes can be given symbolic names
  58. by following each value with :{NAME}
  59. FacilityNames - defines the set of names that are allowed as the
  60. value of the Facility keyword in the message definition.
  61. The set is delimited by left and right parenthesis.
  62. Associated with each facility name is a number that, when
  63. shift it left by 16 bits, gives the bit pattern to logically
  64. OR with the Severity value and MessageId to come up with the
  65. full 32-bit message code. The default value of this keyword
  66. is:
  67. FacilityNames=(System=0x0FF
  68. Application=0xFFF
  69. )
  70. Facility codes occupy the low order 12 bits of the high
  71. order 16-bits of a 32-bit message code. Any facility code
  72. that does not fit in 12 bits is an error. This allows for
  73. 4096 facility codes. The first 256 are reserved for
  74. use by the system software.
  75. The facility codes can be given symbolic names by following
  76. each value with :{NAME}
  77. LanguageNames - defines the set of names that are allowed as the
  78. value of the Language keyword in the message definition.
  79. The set is delimited by left and right parenthesis.
  80. Associated with each language name is a number and a file
  81. name that will be used to name the binary output file that
  82. will contain all of the message text for that language. The
  83. number corresponds to the Language Id tag to use in the
  84. resource table. The number is separate from the file name
  85. with a colon. The initial value of this keyword is:
  86. LanguageNames=(English=1:MSG00001)
  87. Any new names that an application defines in its .mc file
  88. which don't override any of the builtin names will be added
  89. to the list of valid languages. This allows an application
  90. to support private languages with descriptive names.
  91. If the message file contains messages for languages that
  92. must be represented in separate codepages, the optional
  93. fourth (4th) parameter may be used to specify the codepage
  94. that the messages for that Language's messages are in.
  95. LanguageNames=(Japanese=411:MSG00411:932)
  96. The default codepage used, if the codepage is not explicitly
  97. specified, is the OEM Codepage of the system.
  98. OutputBase - sets the output radix for the constants output to C
  99. header file for messages. (It does not set the radix for the
  100. SEVERITY and FACILITY constants. These default to HEX and can be
  101. output in decimal using the -d switch.) If present, Outputbase
  102. overwrites the -d switch for message constants in the header file.
  103. Legal values are 10 and 16.
  104. The OutputBase keyword is legal both in the header section and in the
  105. message definition section of the input file. The OutputBase can be
  106. changed as often as desired.
  107. Following the header section are zero or more message definitions.
  108. Each message definition begins with one or more of the following
  109. keywords.
  110. MessageId={|{NUMBER}|+{NUMBER}}
  111. Severity={SEVERITY_NAME}
  112. Facility={FACILITY_NAME}
  113. SymbolicName={NAME}
  114. The MessageId keyword is required to mark the beginning of the
  115. message definition, although its value is optional. If no value is
  116. specified, then the value used will be the last value used for the
  117. facility, plus one. If the value is specified as +{NUMBER} then
  118. the value used will be the last value used for the facility, plus
  119. the number after the plus sign. Otherwise if a numeric value is
  120. given, that will be value used. Any MessageId value that does not
  121. fit in 16 bits is an error.
  122. Severity and Facility are optional keywords that can specify
  123. additional bits to OR into the final 32-bit message code. If either
  124. of these are not specified they default to the value last specified
  125. for a message definition. The initial values of these prior to
  126. processing the first message definition is:
  127. Severity=Success
  128. Facility=Application
  129. The value associated with these keywords must match one of the names
  130. given to the FacilityNames and SeverityNames keywords. The SymbolicName
  131. keyword allows the ISV to associate a C symbolic constant name with the
  132. final 32-bit message code that is a result of ORing together the
  133. MessageId, Severity and Facility bits. The constant definition is
  134. output to the generated .h file with the following format:
  135. //
  136. // {MESSAGETEXT}
  137. //
  138. #define CONSTANT_SYMBOL_NAME ((MessageIdTypedef) 0x12345678)
  139. where the comment before the definition is a copy of the message
  140. text for the first language specified in the message definition.
  141. The CONSTANT_SYMBOL_NAME is the value of the SymbolicName keyword.
  142. The MessageIdTypedef is not output if it is NULL, the default value.
  143. After the message definition keywords, comes one or more message text
  144. definitions. Each message text definition begins with the Language
  145. keyword that identifies which binary output file this message text
  146. is to be output to. Beginning on the very next line is the first
  147. line of the message text. The message text is terminated by a line
  148. containing a single period at the beginning of the line, immediately
  149. followed by a new line. No spaces allowed around keyword. Within
  150. the message text, blank lines and white space are preserved as part
  151. of the message.
  152. Language={LANGUAGE_NAME}
  153. {MESSAGETEXT}
  154. .
  155. Within the message text, several escape sequences are supported for
  156. dynamically formatting the message. The percent sign character (%)
  157. begins all escape sequences.
  158. %0 - This terminates a message text line without a trailing
  159. newline. This can be used to build up long lines or to
  160. terminate the message itself without a trailing newline,
  161. which is useful for prompt messages.
  162. %n!printf format string! - This identifies an insert. The
  163. value of n can be between 1 and 99. The printf format
  164. string must be bracketed by exclamation marks. It is
  165. optional and defaults to !s! if not specified.
  166. The printf format string can contain the * specifier for
  167. either the precision or width components, and if so, they
  168. will consume inserts %n+1 and %n+2 for their values at run
  169. time. MC will print a warning message if an explicit
  170. reference is made to these inserts elsewhere in the message
  171. text.
  172. Inserts must reference a parameter passed to the FormatMessage API
  173. call. It will return an error if a message refers to an insert that
  174. was not passed to the FormatMessage API call.
  175. Any other character following a percent sign, other than a digit will
  176. be formatted in the output message without the percent sign. Some
  177. examples:
  178. %% - will output a single percent sign in the formatted message text.
  179. %n - will output a hard line break when it occurs at the end of a
  180. a line. Useful when FormatMessage is supplying normal line
  181. breaks so the message fits in a certain width.
  182. %r - will output a hard carriage return, without a trailing newline.
  183. %b - will output a space in the formatted message text. This
  184. can be used to insure there are the appropriate number of
  185. trailing spaces in a message text line.
  186. %t - will output a tab in the formatted message text.
  187. %. - will output a single period in the formatted message text.
  188. This can be used to get a single period at the beginning of
  189. a line without terminating the message text definition.
  190. %! - will output a single exclamation point in the formatted
  191. message text. This can be used to get an exclamation point
  192. immediately after an insert without it being mistaken for
  193. the beginning of a printf format string.
  194. Unicode support is not understood yet. If the input file is ASCII
  195. text, do we need an escape sequence to allow input of Unicode values?
  196. Or do we just let them use DBCS in the text file, assuming they have
  197. a text editor that can do this.
  198. 2. Message Compiler (MC)
  199. This program converts .mc message text files into binary files
  200. suitable for inclusion into a .RC file by the resource compiler.
  201. Command line syntax:
  202. MC [-v] [-w] [-s] [-d] [-n] [-h DirSpec] [-e extension] [-r DirSpec] filename[.mc] ...
  203. where:
  204. -v - generates verbose output to stderr.
  205. -w - generates a warning message whenever an insert escape
  206. sequence is seen that is a superset of the type supported
  207. by OS/2 mkmsgf (i.e. anything other than %0 and %n).
  208. Useful for converting old OS/2 message files to this
  209. format.
  210. -s - Add an extra line to the beginning of each message that is
  211. the symbolic name associated with the message id.
  212. -d - Output SEVERITY and FACILTY constants in decimal. Set the
  213. initial output radix for messages to decimal.
  214. -n - Terminates all strings with null's in the message tables.
  215. -e - Specify the extension for the header file. From 1 - 3 chars.
  216. -h DirSpec - specifies the target directory of the generated
  217. .h file. The file name is the name of the .mc file with a
  218. .h extension.
  219. -r DirSpec - specifies the target directory of the generated
  220. .rc file. The file name is the name of the .mc file with a
  221. .rc extension.
  222. filename.mc - specifes one or more input message files that
  223. will be compiled into one or more binary resource
  224. files, one for each language that the message
  225. files contain message text for.
  226. The message compiler reads the .mc file and generates a .h file
  227. containing all the symbolic name definitions. For each LanguageId
  228. that was used to specify message text, it outputs a binary file
  229. containing a message table resource. It also outputs a single .rc
  230. file that contains the appropriate RC syntax to include each binary
  231. file output as a resource with the appropriate name and type ids.
  232. 3. Message Win32 API Calls
  233. DWORD
  234. APIENTRY
  235. FormatMessage(
  236. DWORD dwFlags,
  237. LPVOID lpSource,
  238. DWORD dwMessageId,
  239. DWORD dwLanguageId,
  240. LPSTR lpBuffer,
  241. DWORD nSize,
  242. va_list Arguments
  243. )
  244. Routine Description:
  245. This function formats a message string. Input to this function is a
  246. message definition. It can come from a buffer passed into this
  247. function. It can come from a message table resource in a module
  248. already loaded. Or the caller can ask this function to search the
  249. system message table resource(s) for the message. This function
  250. finds the message definition based on the Message Id and the
  251. Language Id and copies the message text to the output buffer,
  252. processing any imbedded insert sequences if requested.
  253. Arguments:
  254. dwFlags - Specifies options to the formatting process along with how
  255. to interpret the lpSource parameter. The low order 16bits of
  256. this parameter are the maximum width of a line, in characters.
  257. Possible values are:
  258. FORMAT_MESSAGE_ALLOCATE_BUFFER - the lpBuffer is a PVOID * and
  259. nSize is the minimum size to allocate. This function will
  260. then allocate a buffer large enought to hold the formatted
  261. message and store the pointer to the buffer in the location
  262. pointed to by lpBuffer. Caller should free the buffer
  263. with LocalFree when they are done using it.
  264. FORMAT_MESSAGE_IGNORE_INSERTS - insert sequences in the message
  265. definition will be ignored and passed through to the output
  266. buffer as is. Useful for fetching a message for later
  267. formatting. If this flag is set, the lpArguments parameter
  268. is ignored.
  269. FORMAT_MESSAGE_FROM_STRING - lpSource is a pointer to a null
  270. terminated message definition. It can contain insert
  271. sequences just as the message text in the .mc file can.
  272. FORMAT_MESSAGE_FROM_HMODULE - lpSource is a module handle that
  273. contains the message table resource(s) to search. If this
  274. handle is NULL, then the current process's application
  275. image file will be searched.
  276. FORMAT_MESSAGE_FROM_SYSTEM - If the requested message was not
  277. found in lpSource or if lpSource was not examined (i.e. neither
  278. of the preceeding two flags was specified), then this function
  279. will search the system message table resource(s).
  280. FORMAT_MESSAGE_ARGUMENT_ARRAY - If set, specifies that the passed
  281. Arguments parameter is NOT a va_list structure but instead is
  282. just a pointer to an array of 32-bit values that represent
  283. the arguments.
  284. FORMAT_MESSAGE_MAX_WIDTH_MASK - The low order 8 bits specify the
  285. maximum width of each line formatted into the output buffer.
  286. A maximum width of zero, means that no restrictions are
  287. placed on the width, and only the line breaks in the message
  288. definition will be placed in the output buffer. If a non-zero
  289. value is specified, then line breaks in the message definition
  290. text are ignored, and instead line breaks are calculated based
  291. on the maximum width, with white space delimited strings never
  292. being split across a line break. Hard coded line breaks in
  293. the message definition text, that are identified by the %n
  294. escape sequence, are always output to the output buffer.
  295. If the width specified is FORMAT_MESSAGE_MAX_WIDTH_MASK, then
  296. line breaks in the message file are ignored and only hard coded
  297. line breaks are kept and none are generated.
  298. lpSource - specifies where to retrieve the message definition from.
  299. The type of this parameter depends upon the settings in the
  300. dwFlags parameter.
  301. FORMAT_MESSAGE_FROM_HMODULE - lpSource is an hModule of the
  302. module that contains the message table to search.
  303. FORMAT_MESSAGE_FROM_STRING - lpSource is an LPSTR that points
  304. to unformatted message text. It will be scanned for
  305. inserts and formatted accordingly.
  306. If neither of these options is specified, then this parameter is
  307. ignored.
  308. dwMessageId - specifices the 32-bit message identifier that identifies
  309. the message being requested. This parameter is ignored if the
  310. FORMAT_MESSAGE_FROM_STRING flag is specified.
  311. dwLanguageId - specifices the 32-bit language identifier that
  312. identifies the language of the message being requested. This
  313. parameter is ignored if the FORMAT_MESSAGE_FROM_STRING flag is
  314. specified.
  315. lpBuffer - specifies a pointer to a buffer where the formatted message
  316. is to be written. A terminating null byte will also be written.
  317. If the FORMAT_MESSAGE_ALLOCATE_BUFFER flag was specified, then
  318. this parameter points to a 32-bit pointer value that is filled in
  319. by this call with a pointer allocated via LocalAlloc to contain
  320. the text of the message.
  321. nSize - specifies the maximum number of bytes that can be stored in
  322. the output buffer. This parameter is ignore if the
  323. FORMAT_MESSAGE_ALLOCATE_BUFFER flag is set.
  324. Arguments - specifies a pointer to variable number of arguments.
  325. These arguments are used to satisfy insert requests in the
  326. format string. Thus %1 in the format string specifies the
  327. first argument in the variable number of arguments described
  328. by the Arguments parameter; %3 would specify the third, etc.
  329. The interpretation of each 32-bit arguments value depends upon
  330. the formatting information associated with the insert in the
  331. message definition. The default is to treat each pointer as a
  332. pointer to a null terminated string.
  333. By default the Arguments parameter is of type va_list, which is
  334. a language and implementation specific data type for describing
  335. a variable number of arguments. If you do not have a pointer of
  336. type va_list, then specify the FORMAT_MESSAGE_ARGUMENT_ARRAY
  337. flag and pass a pointer to an array of 32-bit values that are
  338. are input to the message formatted as the insert values.
  339. Return Value:
  340. DwORD - Returns the number of bytes actually stored in the output
  341. buffer, excluding the terminating null character. Returns 0 if
  342. an error occurred. Extended error status is available via the
  343. GetLastError API.