Desktop Functions: Smart Device Functions:
|
Search Results for "FormatMessage" in [All]advapi321: RegOpenKey If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error. 2: RegOpenKeyEx If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error. kernel32
static extern uint FormatMessage(uint dwFlags, IntPtr lpSource,
static extern uint FormatMessage( uint dwFlags, IntPtr lpSource,
static extern uint FormatMessage( uint dwFlags, IntPtr lpSource,
static extern uint FormatMessage(uint dwFlags, IntPtr lpSource, uint dwMessageId, uint dwLanguageId, [Out] StringBuilder lpBuffer, uint nSize, string[] Arguments);
<DllImport("Kernel32.dll", EntryPoint:="FormatMessageW", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function FormatMessage(ByVal dwFlags As Integer, ByRef lpSource As IntPtr, ByVal dwMessageId As Integer, ByVal dwLanguageId As Integer, ByRef lpBuffer As [String], ByVal nSize As Integer, ByRef Arguments As IntPtr) As Integer
<DllImport("Kernel32.dll", EntryPoint:="FormatMessageW", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function FormatMessage(ByVal dwFlags As Integer, ByVal lpSource As IntPtr, ByVal dwMessageId As Integer, ByVal dwLanguageId As Integer, <MarshalAs(UnmanageType.LPWStr)> ByRef lpBuffer As String, ByVal nSize As Integer, ByVal Arguments As IntPtr) As Integer
<DllImport("Kernel32.dll", EntryPoint:="FormatMessageW", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function FormatMessage(ByVal dwFlags As Integer, ByVal lpSource As IntPtr, ByVal dwMessageId As Integer, ByVal dwLanguageId As Integer, ByRef lpBuffer As StringBuilder, ByVal nSize As Integer, ByVal Arguments As IntPtr) As Integer To have FormatMessage substitute %1, %2, etc. with arguments you pass it, declare FormatMessage with a string[] for the last parameter and just pass a normal C# string array. You need to include FORMAT_MESSAGE_ARGUMENT_ARRAY in the dwFlags parameter for this to work. If you are trying use FormatMessage to "decode" an error from Marshal.GetLastWin32Error, go take a look at Marshal.ThrowExceptionForHR (http://msdn.microsoft.com/en-us/library/ckxcyk36(v=VS.80).aspx).
uint dwChars= FormatMessage(
uint length = FormatMessage(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, formatPtr, 0, 0, msgBuilder, 101, formatArgs);
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, IntPtr.Zero, (uint)Marshal.GetLastWin32Error(), 0, msgBuilder, 101, null);
static extern uint FormatMessage(uint dwFlags, IntPtr lpSource,
static extern uint FormatMessage( uint dwFlags, IntPtr lpSource,
static extern uint FormatMessage( uint dwFlags, IntPtr lpSource,
static extern int FormatMessage(
static extern uint FormatMessage(uint dwFlags, IntPtr lpSource, uint dwMessageId, uint dwLanguageId, [Out] StringBuilder lpBuffer, uint nSize, string[] Arguments);
<DllImport("Kernel32.dll", EntryPoint:="FormatMessageW", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function FormatMessage(ByVal dwFlags As Integer, ByRef lpSource As IntPtr, ByVal dwMessageId As Integer, ByVal dwLanguageId As Integer, ByRef lpBuffer As [String], ByVal nSize As Integer, ByRef Arguments As IntPtr) As Integer
<DllImport("Kernel32.dll", EntryPoint:="FormatMessageW", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function FormatMessage(ByVal dwFlags As Integer, ByVal lpSource As IntPtr, ByVal dwMessageId As Integer, ByVal dwLanguageId As Integer, <MarshalAs(UnmanageType.LPWStr)> ByRef lpBuffer As String, ByVal nSize As Integer, ByVal Arguments As IntPtr) As Integer
<DllImport("Kernel32.dll", EntryPoint:="FormatMessageW", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function FormatMessage(ByVal dwFlags As Integer, ByVal lpSource As IntPtr, ByVal dwMessageId As Integer, ByVal dwLanguageId As Integer, ByRef lpBuffer As StringBuilder, ByVal nSize As Integer, ByVal Arguments As IntPtr) As Integer To have FormatMessage substitute %1, %2, etc. with arguments you pass it, declare FormatMessage with a string[] for the last parameter and just pass a normal C# string array. You need to include FORMAT_MESSAGE_ARGUMENT_ARRAY in the dwFlags parameter for this to work. If you are trying use FormatMessage to "decode" an error from Marshal.GetLastWin32Error, go take a look at Marshal.ThrowExceptionForHR (http://msdn.microsoft.com/en-us/library/ckxcyk36(v=VS.80).aspx).
static extern int FormatMessage(FORMAT_MESSAGE dwFlags, IntPtr lpSource, int dwMessageId, uint dwLanguageId, out StringBuilder msgOut, int nSize, IntPtr Arguments);
int size = FormatMessage(FORMAT_MESSAGE.ALLOCATE_BUFFER | FORMAT_MESSAGE.FROM_SYSTEM | FORMAT_MESSAGE.IGNORE_INSERTS,
uint dwChars= FormatMessage(
uint length = FormatMessage(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, formatPtr, 0, 0, msgBuilder, 101, formatArgs);
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, IntPtr.Zero, (uint)Marshal.GetLastWin32Error(), 0, msgBuilder, 101, null);
<System.Runtime.InteropServices.DllImport("Kernel32.dll", EntryPoint:="FormatMessageW", SetLastError:=True, CharSet:=System.Runtime.InteropServices.CharSet.Unicode)>
Public Shared Function FormatMessage(ByVal dwFlags As Integer, ByRef lpSource As IntPtr, ByVal dwMessageId As Integer, ByVal dwLanguageId As Integer, ByRef lpBuffer As IntPtr, ByVal nSize As Integer, ByRef Arguments As IntPtr) As Integer
Dim dwChars As Integer = FormatMessage(Format_Message.FORMAT_MESSAGE_ALLOCATE_BUFFER Or Format_Message.FORMAT_MESSAGE_FROM_SYSTEM Or Format_Message.FORMAT_MESSAGE_IGNORE_INSERTS,
public enum FormatMessageFlags : int
public string FormatMessage(uint messageId, FormatMessageFlags flags, string source, params string[] arguments)
flags &= ~FormatMessageFlags.FORMAT_MESSAGE_FROM_STRING;
flags &= ~FormatMessageFlags.FORMAT_MESSAGE_FROM_HMODULE;
flags &= ~FormatMessageFlags.FORMAT_MESSAGE_ARGUMENT_ARRAY;
int length = FormatMessage(flags, formatPtr, messageId, _lcid, buffer, BUFF_SIZE, arguments);
public string FormatMessage(uint messageId, params string[] arguments)
FormatMessageFlags flags = FormatMessageFlags.FORMAT_MESSAGE_FROM_SYSTEM;
? FormatMessageFlags.FORMAT_MESSAGE_ARGUMENT_ARRAY
: FormatMessageFlags.FORMAT_MESSAGE_IGNORE_INSERTS;
int length = FormatMessage(flags, IntPtr.Zero, messageId, _lcid, buffer, BUFF_SIZE, arguments);
public string FormatMessage(uint messageId)
FormatMessageFlags flags = FormatMessageFlags.FORMAT_MESSAGE_FROM_SYSTEM |
FormatMessageFlags.FORMAT_MESSAGE_IGNORE_INSERTS;
int length = FormatMessage(flags, IntPtr.Zero, messageId, _lcid, buffer, BUFF_SIZE, null);
public string FormatMessage(string moduleName, uint messageId, params string[] arguments)
FormatMessageFlags flags = FormatMessageFlags.FORMAT_MESSAGE_FROM_HMODULE;
? FormatMessageFlags.FORMAT_MESSAGE_ARGUMENT_ARRAY
: FormatMessageFlags.FORMAT_MESSAGE_IGNORE_INSERTS;
int length = FormatMessage(flags, modulePtr, messageId, _lcid, buffer, BUFF_SIZE, arguments);
public string FormatMessage(string message, params string[] arguments)
FormatMessageFlags flags = FormatMessageFlags.FORMAT_MESSAGE_FROM_STRING;
? FormatMessageFlags.FORMAT_MESSAGE_ARGUMENT_ARRAY
: FormatMessageFlags.FORMAT_MESSAGE_IGNORE_INSERTS;
int length = FormatMessage(flags, formatPtr, 0, _lcid, buffer, BUFF_SIZE, arguments);
private static extern int FormatMessage(
[MarshalAs(UnmanagedType.I4)] FormatMessageFlags dwFlags,
static extern TODO FormatMessageA(TODO);
Declare Function FormatMessageA Lib "kernel32.dll" (TODO) As TODO 6: GetLastError To retrieve the error message corresponding to this error code, you can use the [Win32Exception] class, as explained in the FormatMessage page (look at the bottom of the page). coredll
[DllImport("coredll", EntryPoint = "FormatMessageW", SetLastError = true)]
private static extern int FormatMessage(FormatMessageFlags dwFlags, IntPtr lpSource,
Declare Function FormatMessageW Lib "coredll.dll" (TODO) As TODO See http://msdn2.microsoft.com/en-us/library/ms679351.aspx for details on the FormatMessage native method.
[DllImport("coredll", EntryPoint = "FormatMessageW", SetLastError = true)]
private static extern int FormatMessage(FormatMessageFlags dwFlags, IntPtr lpSource,
public enum FormatMessageFlags : int
if (FormatMessage(FormatMessageFlags.FORMAT_MESSAGE_FROM_SYSTEM, IntPtr.Zero, win32ErrorCode, 0, sbMsg, sbMsg.Capacity, null) != 0) netapi32
static string FormatMessage(int errCode)
Console.WriteLine(FormatMessage(errCode)); misc9: FAQ
|