Skip to content

Library

The Library class provides an interface for dynamically loading functions from a DLL at runtime, specifying their calling convention and argument types.

  • constructor(libpath: string)
    Initializes a new Library object and loads the library from the specified path.
  • libpath
    The file path to the shared library (e.g., a DLL or SO file).

Methods:

  • getMethod( name: string, callingConvention?: string, resultType?: string, ...argTypes?: string[]): function
    Retrieves a function from the loaded library and specifies its calling convention, return type, and argument types. The function returned can then be called with the appropriate arguments.
  • name: The name of the function to retrieve from the library.
  • callingConvention: (Optional) The calling convention of the function. Defaults to 'stdcall'. Possible values:
    • 'stdcall': Standard calling convention used in Windows API.
    • 'cdecl': C calling convention.
    • 'safecall': Calling convention that guarantees safe exception handling.
    • 'pascal': Pascal calling convention.
    • 'register': Register calling convention, where arguments are passed via CPU registers.
  • resultType: (Optional) The return type of the function (e.g., 'int', 'void', 'double').
  • argTypes: (Optional) A list of argument types for the function (e.g., 'int', 'const char*'). Supported argument types:
    bool, signed char, unsigned char, short, unsigned short, int, unsigned int, int64, unsigned int64, long, unsigned long, float, double, long double,
    bool*, signed char*, unsigned char*, short*, unsigned short*, int*, unsigned int*, int64*, unsigned int64*, long*, unsigned long*, float*, double*, long double*,
    char, char*, const char*, wchar_t, wchar_t*, const wchar_t*, char16_t, char16_t*, const char16_t*,
    void, void*, IUnknown*, IUnknown**, const IUnknown*, IDispatch*, IDispatch**, const IDispatch*, variant*
    int[], bool[], IUnknown*[], char[], char*[], etc
  • Result is a callable function corresponding to the library method, which can be invoked with the necessary arguments.

The usage of this class is best shown in System.Report app:

Example
var lib = new Library(env.dir + io.path.separator + 'nodeacta.reports.dll');
var createReportFunc = lib.getMethod( 'CreateReport',  
  'stdcall',   // calling convention  
  'void',      // result  
  'wchar*[]',  // arg1: variable[]  
  'IUnknown*', // arg2: (name)=> getValue(name) ICallback  
  'wchar*[]',  // arg3: data_source[]  
  'wchar*',    // arg4: outputPath );