DllInterface Class Reference

#include <dll.h>

Detailed Description

Interface for managing dynamic libraries (load, query symbols, ...).

Public Member Functions

MAXON_METHOD Result< void > Unload ()
 
MAXON_METHOD Result< void > Release ()
 
MAXON_METHOD Result< void * > FindSymbolPointer (const CString &symbol) const
 
template<typename T >
MAXON_FUNCTION Result< T > FindSymbol (const CString &symbol) const
 
MAXON_METHOD Result< Binary * > GetBinary () const
 
MAXON_METHOD Result< void > UpdateSymbolData ()
 
MAXON_METHOD Result< UrlGetPath () const
 

Static Public Member Functions

static MAXON_METHOD Result< DllRef > LoadDll (const Url &fileName, Bool registerDll, Bool requireCoreModule, Int systemDependentFlags=-1)
 
static MAXON_METHOD Result< DllRef > GetModule (const void *handle, UInt processId)
 
static MAXON_METHOD Result< void > AddDllPath (const Url &dllDirectory)
 
static MAXON_METHOD Result< void > RemoveDllPath (const Url &dllDirectory)
 
static MAXON_METHOD Result< void > GetLoadedDlls (const ValueReceiver< const DllRef & > &dlls)
 

Private Member Functions

 MAXON_INTERFACE_NONVIRTUAL (DllInterface, MAXON_REFERENCE_NORMAL, "net.maxon.interface.dll")
 

Member Function Documentation

◆ MAXON_INTERFACE_NONVIRTUAL()

MAXON_INTERFACE_NONVIRTUAL ( DllInterface  ,
MAXON_REFERENCE_NORMAL  ,
"net.maxon.interface.dll"   
)
private

◆ LoadDll()

static MAXON_METHOD Result<DllRef> LoadDll ( const Url fileName,
Bool  registerDll,
Bool  requireCoreModule,
Int  systemDependentFlags = -1 
)
static

Loads the dll into memory. When the last reference disappears the dll will be unloaded automatically.

Parameters
[in]fileNameFilename of the dll to load.
[in]registerDllIf true the library will automatically be unloaded before the current module is unloaded. Make sure not to store the reference permanently (otherwise this can't work).
[in]requireCoreModuleSet this to false to load foreign libraries. Otherwise C4D specific symbols must be present.
[in]systemDependentFlagsFlags passed to the underlying OS function which opens the library. LoadLibrary on Windows, and dlopen on macOS and Linux.
Returns
Returns the dll reference or an error.

◆ GetModule()

static MAXON_METHOD Result<DllRef> GetModule ( const void *  handle,
UInt  processId 
)
static

Creates a DllRef from an already loaded module. The dll will not be unloaded when the reference is deleted.

Parameters
[in]handleHandle to the module. This is a HMODULE on Windows and a void* on Linux and OSX.
[in]processIdId of the process that owns the dll.
Returns
Returns the dll reference or an error.

◆ AddDllPath()

static MAXON_METHOD Result<void> AddDllPath ( const Url dllDirectory)
static

Adds a directory to the search path used to locate DLLs for the application (Windows only).

Parameters
[in]dllDirectoryThe directory to be added to the search path.
Returns
OK on success.

◆ RemoveDllPath()

static MAXON_METHOD Result<void> RemoveDllPath ( const Url dllDirectory)
static

Removes a directory from the library search path (Windows only).

Parameters
[in]dllDirectoryThe directory to be removed from the search path.
Returns
OK on success.

◆ GetLoadedDlls()

static MAXON_METHOD Result<void> GetLoadedDlls ( const ValueReceiver< const DllRef & > &  dlls)
static

Returns all loaded dlls which were loaded through DllInterface.

◆ Unload()

MAXON_METHOD Result<void> Unload ( )

Unloads the dll from memory.

Returns
OK on success.

◆ Release()

MAXON_METHOD Result<void> Release ( )

Detaches this object from the system handle so that the dll will be unloaded when the application quits.

Returns
OK on success. @MAXON_ANNOTATION{default=OK}

◆ FindSymbolPointer()

MAXON_METHOD Result<void*> FindSymbolPointer ( const CString symbol) const

Looks for a symbol and returns a generic pointer to it.

Parameters
[in]symbolSymbol to find in the dll.
Returns
Returns pointer to the symbol in the dll.

◆ FindSymbol()

MAXON_FUNCTION Result<T> FindSymbol ( const CString symbol) const

Looks for a symbol and returns the requested type (via cast).

Parameters
[in]symbolSymbol to find in the dll.
Returns
Returns pointer to the symbol in the dll and casts it to the expected type.

◆ GetBinary()

MAXON_METHOD Result<Binary*> GetBinary ( ) const

◆ UpdateSymbolData()

MAXON_METHOD Result<void> UpdateSymbolData ( )

Loads or updates symbol data for dynamic libraries. Depending on the OS (Windows) this has to be triggered manually after all modules have been loaded.

◆ GetPath()

MAXON_METHOD Result<Url> GetPath ( ) const

Returns the location (Url) of the dll.

Returns
Url of the loaded dll.