DeclareFunctionMBS class

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

Platforms to show: All Mac Windows Linux Cross-Platform

DeclareFunctionMBS class

Type Topic Plugin Version macOS Windows Linux iOS Targets
class DynamicDeclares MBS Util Plugin 20.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
The class for a C function call.
Example
// change path if you like to try this on Windows or Linux
Dim d As New DeclareLibraryMBS("/usr/lib/libz.1.dylib")

// zlibVersion
// ZEXTERN Const char * ZEXPORT zlibVersion Of((void));

Dim p As ptr = d.Symbol("zlibVersion")
Dim f As New DeclareFunctionMBS("()Z", p)

Dim n As String = f.Invoke
MsgBox "zlibVersion: "+n

Compared to built-in declares in Xojo, those functions allow a much more dynamic calling of functions with various calling conventions.

We have

Call Modes

Constant Value Description
kCallModeARM "A" ARM calling
kCallModeARMThumb "a" ARM calling in thumb mode
kCallModeCArm64 22 C arm64 call (AArch64)
kCallModeCArmArmhf 30 C arm call (arm hardfloat - e.g. raspberry pi)
kCallModeCDecl "c" x86 specific CDecl
kCallModeCDefault 0 C default function call for current platform
kCallModeCDefaultThis 99 C default function call for current platform with this pointer.
kCallModeCEllipsis 100 C ellipsis function call (named arguments (before ’...’))
kCallModeCEllipsisVarargs 101 C ellipsis function call (variable/unnamed arguments (after ’...’))
kCallModeCX64Win64 7 C x64 Windows standard call
kCallModeCX86Cdecl 1 C x86 platforms standard call
kCallModeCX86Win32FastGnu 4 C x86 Windows GCC fast call
kCallModeCX86Win32FastMs 3 C x86 Windows Microsoft fast call
kCallModeCX86Win32Std 2 C x86 Windows standard call
kCallModeCX86Win32This 70 C ellipsis function call (variable/unnamed arguments (after ’...’))
kCallModeCX86Win32ThisGnu 1 C x86 Windows GCC this call
kCallModeCX86Win32ThisMs 5 C x86 Windows Microsoft this call
kCallModeDefault ":" Default calling conv (platform native)
kCallModeEllipsisVarargs "." C ellipsis function call (variable/unnamed arguments (after ’...’))
kCallModeSysCall "$" SysCall mode
kCallModeSysDefault 200 C default syscall for current platform
kCallModeSysX64SyscallSysV 204 C syscall for x64 System V platforms
kCallModeSysX86Int80HBSD 202 C syscall for x86 BSD platforms
kCallModeSysX86Int80HLinux 201 C syscall for x86 Linux
kCallModeThisCallGNU "#" x86 specific, GNU C++ this calls are cdecl, but keep specific sig char for clarity.

Calling Conventions

Constant Value Description
kCallModeEllipsis "e" C ellipsis function call
kCallModeFastCallGNU "f" C x86 Windows GCC fast call
kCallModeFastCallMS "F" C x86 Windows Microsoft fast call
kCallModePrefix "_" The character to indicate that next character in the signature is a calling convention prefix.
kCallModeStdCall "s" C x86 Windows standard call
kCallModeThisCallMS "+" C x86 Windows Microsoft this call

Types

Constant Value Description
kTypeBool "B" bool
kTypeChar "c" char, 8 bit signed byte
kTypeDouble "d" Double, 64-bit and 8 bytes big.
kTypeEndArg ")" end of arguments symbol.
kTypeFloat "f" Single, 32-bit and 4 bytes big.
kTypeInt "i" 32-bit signed integer.
kTypeInt64 "l" 64-bit signed integer.
kTypeLong "j" 32/64-bit signed integer.
64-bit only for MacOS and Linux in 64-bit application.
Always 32-bit on Windows.
kTypePtr "p" Pointer. Maybe a reference to an object or array.
kTypeShort "s" 16-bit signed integer.
kTypeString "Z" C String with zero byte as terminator.
kTypeStruct "T" Structure
kTypeUnsignedChar "C" 8 bit unsigned byte
kTypeUnsignedInt "I" 32-bit unsigned integer.
kTypeUnsignedInt64 "L" 64-bit unsigned integer.
kTypeUnsignedLong "J" 32/64-bit unsigned integer.
64-bit only for MacOS and Linux in 64-bit application.
Always 32-bit on Windows.
kTypeUnsignedShort "S" 16-bit unsigned integer.
kTypeVoid "v" Nothing to return.

This class has no sub classes.

Some examples using this class:

Blog Entries

Release notes


The items on this page are in the following plugins: MBS Util Plugin.


DeclareCallBackMBS   -   DeclareLibraryMBS


💬 Ask a question or report a problem