Tuesday, August 26, 2008

Extern?

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 you are using Interop services to call into unmanaged code. In this case, the method must also be declared as static, as shown in the following example
A common use of it is for the Windows API. I have a class that containsdeclarations like this:
internal static class API{[DllImport("user32.dll")]internal static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, UIntPtrwParam, IntPtr lParam);}
whereas using the abstract modifier means that the method implementation is not provided in the class.

No comments: