// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Text; namespace E { public partial class MainForm : Form { public MainForm() { InitializeComponent(); } [DllImport("User32.dll",SetLastError=true)] static extern bool HideCaret(System.IntPtr hWnd); [DllImport("kernel32.dll", CharSet=CharSet.Auto)] public static extern int FormatMessage(int dwFlags, string lpSource, int dwMessageId, int dwLanguageId, StringBuilder lpBuffer, int nSize, string[] Arguments); private string FormatMessageWrapper(int err) { StringBuilder sb = new StringBuilder(256); FormatMessage(4096, null, err, 0, sb, sb.Capacity, null); return sb.ToString(); } void Button1Click(object sender, EventArgs e) { textBox1.Focus(); if(!HideCaret(textBox1.Handle)) { MessageBox.Show(FormatMessageWrapper(Marshal.GetLastWin32Error())); } } } }