NativeModule - Kirix Documentation

Developer Resources

NativeModule

Overview

The NativeModule class provides the ability to access shared libraries such as DLLs, SOs, and DYLIBs.

Constructor

NativeModule(filename : String)

Arguments

filename
The filename of the dll, so, or dylib file to load

Properties

NativeType.Char
Type indicator for a single-byte character ('C' char type)
NativeType.Byte
Type indicator for a single byte ('C' unsigned char type)
NativeType.Word
Type indicator for a 16-bit value ('C' short int type)
NativeType.Int32
Type indicator for a 16-bit value ('C' int type)
NativeType.Int64
Type indicator for a 64-bit value ('C' long long type)
NativeType.Float
Type indicator for a 32-bit floating point value ('C' float type)
NativeType.Double
Type indicator for a 64-bit floating point value ('C' double type)
NativeType.String8
Type indicator for an 8-bit character string ('C' char* type)
NativeType.String16
Type indicator for an 16-bit character string ('C' unsigned short* type)
NativeType.String32
Type indicator for an 32-bit character string ('C' unsigned long* type)
NativeCall.Default
Use the platform's default calling conventions
NativeCall.CDecl
Use C calling conventions
NativeCall.StdCall
Use stdcall calling conventions

Methods

NativeModule.getFunction
Load a function from the shared library for invocation
NativeModule.isOk
Determines if a shared library loaded properly

Example

// the following demonstrates loading the WIN32 MessageBox
// API call from user32.dll, attaching it to a function,
// and invoking it with parameters

var mod = new NativeModule("user32.dll");

var MB_OKCANCEL = 1;

var Win32MessageBox = mod.getFunction(
                           NativeCall.StdCall,  // calling convention
                           NativeType.Int32,    // return value
                           "MessageBoxA",       // function name
                           NativeType.Int32,    // parent window handle
                           NativeType.String8,  // message body string
                           NativeType.String8,  // message box caption
                           NativeType.Int32);   // message box type

Win32MessageBox(0, "This is a message box", "Win32 Message Box", MB_OKCANCEL);

NativeModule.getFunction

static function NativeModule.getFunction(function_name : String) : Integer

Arguments

function_name
The name of the function as it appears in the shared library

Returns

A callable function object

Description

Calling getFunction loads a function from a shared library for invocation. The function's parameters, return type, and calling convention must be specified.

NativeModule.isOk

function NativeModule.isOk() : Boolean

Returns

True if the shared library is loaded, false otherwise

Description

Determines whether the object is attached to a valid shared library and that the library loaded properly.