Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

DllImportAttribute Constructor

Initializes a new instance of the DllImportAttribute class with the name of the DLL containing the method to import.

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

public DllImportAttribute (
	string dllName
)
public DllImportAttribute (
	String dllName
)
public function DllImportAttribute (
	dllName : String
)

Parameters

dllName

The name of the DLL that contains the unmanaged method.

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.

using System;
using System.Runtime.InteropServices;

class Example
{
    // Use DllImport to import the Win32 MessageBox function.
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    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);
    }
}

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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.