DllImportAttribute.EntryPoint 欄位

定義

指示要呼叫的 DLL 進入點 (Entry Point) 的名稱或序數。

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

欄位值

範例

下列程式代碼範例示範如何使用 DllImportAttribute 屬性來匯入 Win32 MessageBox 函式。 程式代碼範例會 EntryPoint 使用 屬性來指定要匯入的函式,然後將名稱變更為 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 名稱,也可以依序數識別進入點。 序數前面會加上 # 符號,例如 #1。 如果您省略此欄位,Common Language Runtime 會使用標示 DllImportAttribute為 的 the.NET 方法名稱。

如需詳細資訊,請參閱 識別 DLL 中的函式。 如需示範如何使用 欄位的 EntryPoint 範例,請參閱 指定進入點

適用於

另請參閱