DllImportAttribute.EntryPoint 字段

定义

指示要调用的 DLL 入口点的名称或序号。Indicates the name or ordinal of the DLL entry point to be called.

public: System::String ^ EntryPoint;
public string EntryPoint;
val mutable EntryPoint : string
Public EntryPoint As String 

字段值

示例

下面的代码示例演示如何使用 DllImportAttribute 特性导入 Win32 MessageBox 函数。The following code example shows how to use the DllImportAttribute attribute to import the Win32 MessageBox function. 此代码示例使用 EntryPoint 属性指定要导入的函数,然后将名称更改为 MyNewMessageBoxMethodThe code example uses the EntryPoint property to specify the function to import and then changes the name to MyNewMessageBoxMethod.

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);
    }
}
Imports System.Runtime.InteropServices

Module 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")> _
    Function MyNewMessageBoxMethod(ByVal hwnd As IntPtr, ByVal t As String, ByVal caption As String, ByVal t2 As UInt32) As Integer
    End Function


    Sub Main()
        ' Call the MessageBox function using platform invoke.
        MyNewMessageBoxMethod(New IntPtr(0), "Hello World!", "Hello Dialog", 0)
    End Sub

End Module

注解

您可以通过提供指示包含入口点的 DLL 的名称的字符串指定入口点名称,也可以通过其序号标识入口点。You can specify the entry-point name by supplying a string indicating the name of the DLL containing the entry point, or you can identify the entry point by its ordinal. 序数前面带有 # 号,例如 #1。Ordinals are prefixed with the # sign, for example, #1. 如果省略此字段,则公共语言运行时将使用标记有 DllImportAttribute的 the.NET 方法的名称。If you omit this field, the common language runtime uses the name of the.NET method marked with the DllImportAttribute.

有关其他信息,请参阅在 dll 中标识函数For additional information, see Identifying Functions in DLLs. 有关演示如何使用 EntryPoint 字段的示例,请参阅指定入口点For examples showing how to use the EntryPoint field, see Specifying an Entry Point.

适用于

另请参阅