using System; using System.Collections.Generic; using System.Text; namespace DllImportTest { class Program { // DllImport属性をしてメソッドを定義 [System.Runtime.InteropServices.DllImport("kernel32.dll")] public static extern bool GetComputerName(StringBuilder buffer, ref uint size); static void Main(string[] args) { StringBuilder buffer = new StringBuilder(256); uint size = 256; // API呼び出し if (GetComputerName(buffer, ref size)) { System.Console.WriteLine("Computer name: {0}", buffer.ToString()); } else { System.Console.WriteLine("GetComputerName() - error"); } } } }