DllImportAttribute(String) 생성자

정의

가져올 메서드가 포함된 DLL의 이름을 사용하여 DllImportAttribute 클래스의 새 인스턴스를 초기화합니다.

public:
 DllImportAttribute(System::String ^ dllName);
public DllImportAttribute (string dllName);
new System.Runtime.InteropServices.DllImportAttribute : string -> System.Runtime.InteropServices.DllImportAttribute
Public Sub New (dllName As String)

매개 변수

dllName
String

관리되지 않는 메서드를 포함하는 DLL의 이름입니다. DLL이 어셈블리에 포함되어 있는 경우 이 이름에는 어셈블리 표시 이름이 포함될 수 있습니다.

예제

다음 코드 예제에서는 특성을 사용하여 DllImportAttribute Win32 MessageBox 함수를 가져오는 방법을 보여줍니다. 그런 다음, 코드 예제는 가져온 메서드를 호출합니다.

using System;
using System.Runtime.InteropServices;

class Example
{
    // Use DllImport to import the Win32 MessageBox function.
    [DllImport("user32.dll", CharSet = CharSet.Unicode)]
    public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);
    
    static void Main()
    {
        // Call the MessageBox function using platform invoke.
        MessageBox(new IntPtr(0), "Hello World!", "Hello Dialog", 0);
    }
}
Imports System.Runtime.InteropServices

Module Example

    ' Use DllImport to import the Win32 MessageBox function.
    <DllImport("user32.dll", CharSet:=CharSet.Unicode)> _
    Function MessageBox(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.
        MessageBox(New IntPtr(0), "Hello World!", "Hello Dialog", 0)
    End Sub

End Module

설명

예를 들어 링커 또는 /linkresource 컴파일러 옵션을 사용하여 관리되지 않는 DLL 파일이 어셈블리에 포함된 경우 어셈블리 표시 이름을 의 dllName일부로 지정할 수 있습니다. 예를 들어 명명 unmanaged.dll 된 관리되지 않는 DLL이 관리 MyAssembly되는 어셈블리에 포함된 경우 다음 코드와 같이 특성을 지정할 수 있습니다.

[DllImport("unmanaged.dll, MyAssembly, Version= 1.0.0.0,"
    "Culture=neutral, PublicKeyToken=a77e0ba5eab10125")]
int SomeFuncion1(int parm);
[DllImport("unmanaged.dll, MyAssembly, Version= 1.0.0.0," +
    "Culture=neutral, PublicKeyToken=a77e0ba5eab10125")]
internal static extern int SomeFuncion1(int parm);
<DllImport("unmanaged.dll, MyAssembly, Version= 1.0.0.0," +
    "Culture=neutral, PublicKeyToken=a77e0ba5eab10125")>
Friend Shared Function DummyFuncion1(parm As Integer) As Integer
End Function

적용 대상