FormatMessage

C# Signature:

[DllImport("kernel32.dll")]
static extern uint FormatMessage(uint dwFlags, IntPtr lpSource,
   uint dwMessageId, uint dwLanguageId, [Out] StringBuilder lpBuffer,
   uint nSize, IntPtr Arguments);

// the version, the sample is built upon:
[DllImport("Kernel32.dll", SetLastError=true)]
static extern uint FormatMessage( uint dwFlags, IntPtr lpSource, 
   uint dwMessageId, uint dwLanguageId, ref IntPtr lpBuffer, 
   uint nSize, IntPtr pArguments);

// the parameters can also be passed as a string array:
[DllImport("Kernel32.dll", SetLastError=true)]
static extern uint FormatMessage( uint dwFlags, IntPtr lpSource, 
   uint dwMessageId, uint dwLanguageId, ref IntPtr lpBuffer, 
   uint nSize, string[] Arguments);

// simplified for usability
[DllImport("kernel32.dll")]
static extern int FormatMessage(
    FORMAT_MESSAGE dwFlags,
    IntPtr lpSource,
    int dwMessageId,
    uint dwLanguageId,
    out StringBuilder msgOut,
    int nSize,
    IntPtr Arguments
);

C# Signature:

VB.NET Signature:

VB.NET Signature:

VB.NET Signature:

Sample Code:

Sample Code:

Sample Code:

Sample Code:

Alternative Managed API:

Última actualización