DllImportAttribute.EntryPoint 字段

定义

指示要调用的 DLL 入口点的名称或序号。

C#
public string EntryPoint;
C#
public string? EntryPoint;

字段值

示例

下面的代码示例演示如何使用 DllImportAttribute 特性导入 Win32 MessageBox 函数。 该代码示例使用 EntryPoint 属性指定要导入的函数,然后将名称更改为 MyNewMessageBoxMethod

C#
using System;
using System.Runtime.InteropServices;

class Example
{
    // Use DllImport to import the Win32 MessageBox function.
    // Specify the method to import using the EntryPoint field and 
    // then change the name to MyNewMessageBoxMethod.
    [DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "MessageBox")]
    public static extern int MyNewMessageBoxMethod(IntPtr hWnd, String text, String caption, uint type);
    
    static void Main()
    {
        // Call the MessageBox function using platform invoke.
        MyNewMessageBoxMethod(new IntPtr(0), "Hello World!", "Hello Dialog", 0);
    }
}

注解

可以通过提供一个字符串来指定入口点名称,该字符串指示包含入口点的 DLL 的名称,也可以按其序号标识入口点。 序号的前缀为 # 符号,例如 #1。 如果省略此字段,公共语言运行时将使用标 DllImportAttribute有 the.NET 方法的名称。

有关详细信息,请参阅 标识 DLL 中的函数。 有关如何使用 EntryPoint 字段的示例,请参阅 指定入口点

适用于

产品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

另请参阅