Monday, March 1, 2010

How to import dll C#

make a console project and paste the is the code :

using System;
using System.Runtime.InteropServices;
class Example
// Use DllImport to import the Win32 MessageBox function.
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);

remeber the name MessageBox is unique entry in this dll.

The extern modifier is used to declare a method that is implemented externally. A common use of the extern modifier is with the DllImport attribute when using Interop services to call into unmanaged code; in this case, the method must also be declared as static

after execution :