DllImport

The DllImport aspect imports native methods from the given dynamic library. The aspect takes the name of the library (a .dll, .so, or .dylib, depending on platform) as a parameter. Optionally an EntryPoint can be provided to more precisely specify the native name of the method to be imported, if it does not match the local declaration.

The DllImport aspect can only be applied to static methods that have been marked as external (Oxygene) or extern (C#) or __external (Swift) or native (Java).

Note that DllImport will cause the executable to fail to load entirely, if any imported symbol is not available at runtime. By contrast, the DelayLoadDllImport aspect can be used to dynamically import symbols only if they are available at runtime, and allow code to fail or workmaround missing symbols gracefully (for example on older versions of an operating system).

.NET and Island Only

The DllExport aspect is available only on the .NET and Island-backed platforms.

type
  MyClass = public class 
  public  
    [DllImport("Foo.dll")]
    class method SomeNativeCode(); external;
  end;
public class MyClass
{
    [DllImport("Foo.dll")]
    public static extern void SomeNativeCode();
}
public class MyClass {
    @DllImport("Foo.dll")
    public extern func SomeNativeCode()
}
public class MyClass {
    @DllImport("Foo.dll")
    public static extern void SomeNativeCode();
}

See Also