Imports System.Runtime.InteropServices
Public Class Form1
<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
End Function
Public Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Public ErrorString = "12345678"
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Bytes As Long
Static aa As IntPtr
Bytes = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, aa, Err.LastDllError, 0, ErrorString, 128, aa)
lstResults.Items.Add(Bytes)
End Sub
End Class