Code
[DllImport("kernel32.dll",
EntryPoint = "GetComputerName",
ExactSpelling = false,
SetLastError = true)]
static extern bool GetComputerName(
[MarshalAs(UnmanagedType.LPArray)] byte[] lpBuffer,
[MarshalAs(UnmanagedType.LPArray)] Int32[] nSize);
public Form1()
{
InitializeComponent();
byte[] str = new byte[20];
Int32[] len = new Int32[1];
len[0] = 20;
GetComputerName(str, len);
MessageBox.Show(System.Text.Encoding.ASCII.GetString(str));
}
[DllImport("kernel32.dll",
EntryPoint = "GetComputerName",
ExactSpelling = false,
SetLastError = true)]
static extern bool GetComputerName(
[MarshalAs(UnmanagedType.LPArray)] byte[] lpBuffer,
[MarshalAs(UnmanagedType.LPArray)] Int32[] nSize);
public Form1()
{
InitializeComponent();
byte[] str = new byte[20];
Int32[] len = new Int32[1];
len[0] = 20;
GetComputerName(str, len);
MessageBox.Show(System.Text.Encoding.ASCII.GetString(str));
}