Table of Contents

Class SharedObject

Namespace
Sdl3Sharp.Utilities
Assembly
Sdl3Sharp.dll

Represents a system-dependent code library (shared object) that is programmatically loadable at runtime

public sealed class SharedObject : IDisposable
Inheritance
SharedObject
Implements
Inherited Members

Remarks

Windows calls these "DLLs", Linux calls them "shared libraries", etc.

Constructors

SharedObject(string)

Create and loads a new SharedObject from a specified file

public SharedObject(string file)

Parameters

file string

The system-dependent name of the shared object file. Could be a file path or some kind of special name.

Remarks

Creating a new SharedObject instance also loads the specified shared object file through system-specific manners.

In contrast to most of the remaining API which uses the Try-method pattern, this constructor intentionally fails by throwing an exception. If you want to handle failures wrap the call to this constructor in a try-block, and check TryGet(out string?) for more information when catching a SdlException.

Exceptions

SdlException

Couldn't load the specified shared object file (check TryGet(out string?) for more information)

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Remarks

Note: after disposing a SharedObject, all of the resulting symbol handles from calls to TryLoadSymbol(string, out nint) during its lifetime are now invalid! Do not try to dereference such a handle after disposing the respective SharedObject!

~SharedObject()

protected ~SharedObject()

Remarks

Note: after disposing a SharedObject, all of the resulting symbol handles from calls to TryLoadSymbol(string, out nint) during its lifetime are now invalid! Do not try to dereference such a handle after disposing the respective SharedObject!

TryLoadSymbol(string, out nint)

Tries to look up the handle of a named symbol in the SharedObject

public bool TryLoadSymbol(string name, out nint symbol)

Parameters

name string

The name of the symbol to look up

symbol nint

The handle the symbol with the specified name when this method returns true; otherwise, Zero

Returns

bool

true if a symbol with the specified name was found and succesfully loaded; otherwise, false (check TryGet(out string?) for more information)

Remarks

This method can only look up exported C symbol names. Other languages may have name mangling and intrinsic language support that varies from compiler to compiler.

If you want to call a resulting symbol as a function, make sure you declare the function pointer signature with the same calling convention as the actual library function. Your code will crash mysteriously if you do not do this.

Note: Resulting symbol handles are no longer valid after disposing the respective SharedObject!