Export (0) Print
Expand All

DllImportAttribute Class

Indicates that the attributed method is exposed by an unmanaged dynamic-link library (DLL) as a static entry point.

Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)

[AttributeUsageAttribute(AttributeTargets::Method, Inherited=false)] 
[ComVisibleAttribute(true)] 
public ref class DllImportAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Method, Inherited=false) */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class DllImportAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Method, Inherited=false) 
ComVisibleAttribute(true) 
public final class DllImportAttribute extends Attribute

You can apply this attribute to methods.

The DllImportAttribute attribute provides the information needed to call a function exported from an unmanaged DLL. As a minimum requirement, you must supply the name of the DLL containing the entry point.

You apply this attribute directly to C# and C++ method definitions; however, the Visual Basic compiler emits this attribute when you use the Declare statement. For complex method definitions that include BestFitMapping, CallingConvention, ExactSpelling, PreserveSig, SetLastError, or ThrowOnUnmappableChar fields, you apply this attribute directly to Visual Basic method definitions.

Note   JScript does not support this attribute. You can use C# or Visual Basic wrapper classes to access unmanaged API methods from JScript programs.

For additional information about using the platform invoke service to access functions in unmanaged DLLs, see Consuming Unmanaged DLL Functions.

NoteNote

The DllImportAttribute does not support marshaling of generic types.

The following code example shows how to use the DllImportAttribute attribute to import the Win32 MessageBox function. The code example then calls the imported method.

No code example is currently available or this language may not be supported.

System.Object
   System.Attribute
    System.Runtime.InteropServices.DllImportAttribute

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft