using System.Windows.Forms; using System.Runtime.InteropServices; using System; using System.Drawing; public class Window : Form { [DllImport("user32.dll")] public static extern int MessageBox(int h, string m, string c, int type); [DllImport("kernel32")] static extern void GetSystemInfo(ref SYSTEM_INFO pSI); [DllImport("user32.dll")] static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); [StructLayout(LayoutKind.Sequential)] public struct SYSTEM_INFO { public uint dwOemId; public uint dwPageSize; public uint lpMinimumApplicationAddress; public uint lpMaximumApplicationAddress; public uint dwActiveProcessorMask; public uint dwNumberOfProcessors; public uint dwProcessorType; public uint dwAllocationGranularity; public uint dwProcessorLevel; public uint dwProcessorRevision; } public Window() { Button bt = new Button(); bt.Location = new Point(20,30); bt.Click += bt_Click; Controls.Add(bt); } void bt_Click(object sender, EventArgs e) { //MessageBox(0, "API message box", "API demo", 0); try { SYSTEM_INFO s = new SYSTEM_INFO(); GetSystemInfo(ref s); MessageBox(0, s.dwNumberOfProcessors.ToString(), "API demo", 0); } catch(Exception) {} } static void Main() { Application.Run(new Window()); } }