DllImportAttribute(String) Construtor
Definição
Inicializa uma nova instância da classe DllImportAttribute com o nome da DLL que contém o método a ser importado.Initializes a new instance of the DllImportAttribute class with the name of the DLL containing the method to import.
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)
Parâmetros
- dllName
- String
O nome da DLL que contém o método não gerenciado.The name of the DLL that contains the unmanaged method. Isso pode incluir um nome de exibição do assembly se a DLL estiver incluída em um assembly.This can include an assembly display name, if the DLL is included in an assembly.
Exemplos
O exemplo de código a seguir mostra como usar o DllImportAttribute atributo para importar a MessageBox função do Win32.The following code example shows how to use the DllImportAttribute attribute to import the Win32 MessageBox function. Em seguida, o exemplo de código chama o método importado.The code example then calls the imported method.
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
Comentários
Se um arquivo DLL não gerenciado for incluído em um assembly, por exemplo, usando o vinculador ou a opção de /linkresource compilador, você poderá especificar o nome de exibição do assembly como parte do dllName .If an unmanaged DLL file is included in an assembly, for example, by using the linker or the /linkresource compiler option, you can specify the assembly display name as part of dllName. Por exemplo, se uma DLL não gerenciada chamada unmanaged.dll for incluída em um assembly gerenciado chamado MyAssembly , o atributo poderá ser especificado conforme mostrado no código a seguir.For example, if an unmanaged DLL named unmanaged.dll is included in a managed assembly named MyAssembly, the attribute might be specified as shown in the following code.
[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