溫馨提示×

extern c#如何調用外部函數

c#
小樊
116
2024-08-21 11:23:28
欄目: 編程語言

在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方法中調用了該函數。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女