Exemple #1
0
 /// <summary>
 /// Format a message.
 /// </summary>
 /// <param name="module">The module containing the message.</param>
 /// <param name="message_id">The ID of the message.</param>
 /// <returns>The message. Empty string on error.</returns>
 public static string FormatMessage(SafeLoadLibraryHandle module, uint message_id)
 {
     if (Win32NativeMethods.FormatMessage(FormatFlags.AllocateBuffer | FormatFlags.FromHModule
                                          | FormatFlags.FromSystem | FormatFlags.IgnoreInserts,
                                          module.DangerousGetHandle(), message_id, 0, out SafeLocalAllocBuffer buffer, 0, IntPtr.Zero) > 0)
     {
         using (buffer) {
             return(Marshal.PtrToStringUni(buffer.DangerousGetHandle()).Trim());
         }
     }
     return(string.Empty);
 }