Kernel32FormatMessage Method

Formats a message string. The function requires a message definition as input. The message definition can come from a buffer passed into the function. It can come from a message table resource in an already-loaded module. Or the caller can ask the function to search the system's message table resource(s) for the message definition. The function finds the message definition in a message table resource based on a message identifier and a language identifier. The function copies the formatted message text to an output buffer, processing any embedded insert sequences if requested.

Definition

Namespace: DevCase.Win32.NativeMethods
Assembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("Kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static int FormatMessage(
	FormatMessageFlags flags,
	IntPtr source,
	uint messageId,
	uint languageId,
	ref IntPtr refBuffer,
	uint size,
	string[] arguments
)

Parameters

flags  FormatMessageFlags
The formatting options, and how to interpret the source parameter.

The low-order byte of flags parameter specifies how the function handles line breaks in the output buffer. The low-order byte can also specify the maximum width of a formatted output line.

source  IntPtr
The location of the message definition.

The type of this parameter depends upon the settings in the flags parameter.

messageId  UInt32
The message identifier for the requested message.

This parameter is ignored if flags includes FromString.

languageId  UInt32
The language identifier for the requested message.

This parameter is ignored if flags includes FromString.

refBuffer  IntPtr
A pointer to a buffer that receives the null-terminated string that specifies the formatted message.

If flags includes AllocateBuffer, the function allocates a buffer using the LocalAlloc function, and places the pointer to the buffer at the address specified in refBuffer.

This buffer cannot be larger than 64K bytes.

size  UInt32
If the AllocateBuffer flag is not set, this parameter specifies the size of the output buffer.

If AllocateBuffer is set, this parameter specifies the minimum number of characters to allocate for an output buffer.

Thhe output buffer cannot be larger than 64K bytes.

arguments  String
An array of values that are used as insert values in the formatted message.

A %1 in the format string indicates the first value in the Arguments array; a %2 indicates the second argument; and so on.

The interpretation of each value depends on the formatting information associated with the insert in the message definition. The default is to treat each value as a pointer to a null-terminated string.

Return Value

Int32
If the function succeeds, the return value is the number of characters stored in the output buffer, excluding the terminating null character.

If the function fails, the return value is .

To get extended error information, call GetLastWin32Error.

Remarks

See Also