DelayLoadDllImport

The DelayLoadDllImport aspect works similar to DllImport and 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.

Different than DllImport, the DelayLoadDllImport aspect will not create a hard binding to the imported symbol, but instead the symbol will be attempted to be mapped dynamically at runtime, when needed. This will all the compiled code to run even if the symbol is not available (for example on older versions of an operating system), as long as callers verify the symbol is available by checking against nil/null before calling it. (By contrast, symbols imported with DllImport will cause the executable to fail to load entirely, if any imported symbol is not available at runtime.

The DelayLoadDllImport 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 unlike DllImport, DelayLoadDllImport does not automatically apply mangling to the specified symbol name override. The actual mangled name of the symbol as it is present in the binary needs to be specified as pafrt of the attribute

Island Only

The DelayLoadDllImport aspect is available only on the Island-backed platforms.

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

See Also