How to call native windows dll function in C#

1 Answer

0 votes
using System.Runtime.InteropServices;

namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        public static extern int MessageBox(IntPtr h, string m, string c, int type);

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int rv = MessageBox(IntPtr.Zero, "Message Text", "Title", 0);
        }
    }
}



/*
 * run:
 *
 * 
 * 
 */

 



answered Aug 19, 2023 by avibootz
...