extern c#如何调用外部函数

   2024-10-01 9270
核心提示:在C#中调用外部函数可以使用DllImport属性来引入外部函数的定义。以下是一个简单的示例:using System;using System.Runtime.Int

在C#中调用外部函数可以使用DllImport属性来引入外部函数的定义。以下是一个简单的示例:

using System;using System.Runtime.InteropServices;class Program{    [DllImport("user32.dll")]    public static extern int MessageBox(IntPtr hWnd, string text, string caption, uint type);    static void Main()    {        MessageBox(IntPtr.Zero, "Hello World!", "MessageBox Example", 0);    }}

在上面的示例中,我们通过DllImport属性引入了user32.dll中的MessageBox函数,并在Main方法中调用了该函数。

 
举报打赏
 
更多>同类物流大全
推荐图文
推荐物流大全
点击排行

网站首页  |  关于我们  |  联系方式网站留言    |  赣ICP备2021007278号