Platforms to show: All Mac Windows Linux Cross-Platform
Back to DeclareFunctionMBS class.
DeclareFunctionMBS.ClearParameters
Function:
Clears all parameters.
Notes: Sets them all to zero/nil.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | DynamicDeclares | MBS Util Plugin | 20.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes: Sets them all to zero/nil.
DeclareFunctionMBS.Constructor(Signature as String, FunctionPtr as Ptr)
Function:
The constructor.
Example:
Notes:
Pass the signature and function pointer from a C function.
If signature is incorrect, the application will probably crash with stack corruption.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | DynamicDeclares | MBS Util Plugin | 20.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
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
Pass the signature and function pointer from a C function.
If signature is incorrect, the application will probably crash with stack corruption.
DeclareFunctionMBS.Invoke as Variant
Function:
Invokes the function.
Example:
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | DynamicDeclares | MBS Util Plugin | 20.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
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
See also:
DeclareFunctionMBS.Invoke(Parameters() as Variant) as Variant
Function:
Invokes the function.
Notes:
First calls SetParameters with the given array to set parameters.
Then invokes the function.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | DynamicDeclares | MBS Util Plugin | 20.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes:
First calls SetParameters with the given array to set parameters.
Then invokes the function.
See also:
DeclareFunctionMBS.ParameterBoolean(Index as Integer) as Boolean
Function:
The parameter as boolean.
Notes:
You can get and set value here.
(Read and Write computed property)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
property | DynamicDeclares | MBS Util Plugin | 20.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes:
You can get and set value here.
(Read and Write computed property)
DeclareFunctionMBS.ParameterDouble(Index as Integer) as Double
Function:
The parameter value as double.
Notes:
You can get and set value here.
(Read and Write computed property)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
property | DynamicDeclares | MBS Util Plugin | 20.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes:
You can get and set value here.
(Read and Write computed property)
DeclareFunctionMBS.ParameterInteger(Index as Integer) as Int64
Function:
The parameter as integer value.
Notes:
You can get and set value here.
(Read and Write computed property)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
property | DynamicDeclares | MBS Util Plugin | 20.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes:
You can get and set value here.
(Read and Write computed property)
Some examples using this property:
DeclareFunctionMBS.ParameterPointer(Index as Integer) as Ptr
Function:
The parameter as pointer value.
Notes:
You can get and set value here.
(Read and Write computed property)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
property | DynamicDeclares | MBS Util Plugin | 20.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes:
You can get and set value here.
(Read and Write computed property)
DeclareFunctionMBS.ParameterSingle(Index as Integer) as Single
Function:
The parameter as single value.
Notes:
You can get and set value here.
(Read and Write computed property)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
property | DynamicDeclares | MBS Util Plugin | 20.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes:
You can get and set value here.
(Read and Write computed property)
DeclareFunctionMBS.ParameterString(Index as Integer) as String
Function:
The parameter as string value.
Example:
Notes:
To avoid crashes, we only read strings from parameters with type string or pointer.
But you can assign a string value to all types, which may not make sense for numbers.
You can get and set value here.
(Read and Write computed property)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
property | DynamicDeclares | MBS Util Plugin | 20.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Example:
// We try to run strstr on C Library on macOS to find string in string with strstr as example:
Dim d As New DeclareLibraryMBS("/usr/lib/libc.dylib")
// char *strstr(Const char *__big, Const char *__little);
Dim p As ptr = d.Symbol("strstr")
Dim f As New DeclareFunctionMBS("(ZZ)Z", p)
f.ParameterString(0) = "Hello World!"
f.ParameterString(1) = "World"
Dim n1 As String = f.Invoke
// gives back World! as that was found
f.ParameterString(0) = "Hello World!"
f.ParameterString(1) = "xxx"
Dim n2 As String = f.Invoke
// gives empty string as not found
Break // see in debugger
To avoid crashes, we only read strings from parameters with type string or pointer.
But you can assign a string value to all types, which may not make sense for numbers.
You can get and set value here.
(Read and Write computed property)
DeclareFunctionMBS.ParameterValue(Index as Integer) as Variant
Function:
Get or set the value as variant.
Notes:
We automatically convert values based on the parameter type.
The class stores reference to the variant when setting to make sure strings and MemoryBlocks are not freed too early.
You can get and set value here.
(Read and Write computed property)
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
property | DynamicDeclares | MBS Util Plugin | 20.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Notes:
We automatically convert values based on the parameter type.
The class stores reference to the variant when setting to make sure strings and MemoryBlocks are not freed too early.
You can get and set value here.
(Read and Write computed property)
DeclareFunctionMBS.SetParameters(paramArray Parameters as Variant)
Function:
Set all parameters together with passing arguments to this function.
Example:
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | DynamicDeclares | MBS Util Plugin | 20.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Example:
// We try to run sysctlbyname on macOS
Dim d As New DeclareLibraryMBS("/usr/lib/libc.dylib")
// int sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen);
Dim p As ptr = d.Symbol("sysctlbyname")
'const char* -> CString for name -> Z
'void* -> pointer to data -> p
'size_t * -> pointer to 32/64 bit integer for length -> p
'void* -> pointer to data -> p
'size_t -> 32/64bit unsigned int -> L in 64-bit
Dim f As New DeclareFunctionMBS("(ZpppL)i", p)
Dim mData As New MemoryBlock(8)
Dim mLen As New MemoryBlock(8)
Dim pData As ptr = mData
dim pLen as ptr = mLen
mLen.UInt64Value(0) = mData.Size
f.SetParameters "hw.ncpu", pData, pLen, Nil, 0
Dim n As Integer = f.Invoke
// result is zero on result or -1 on failure
Dim CPUCount As Integer = mData.UInt32Value(0)
If n = 0 Then
MsgBox "CPU count: "+Str(CPUCount)
Else
MsgBox "Failed."
End If
Break // see in debugger
See also:
DeclareFunctionMBS.SetParameters(Parameters() as Variant)
Function:
Sets all arguments by passing an array of values.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | DynamicDeclares | MBS Util Plugin | 20.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
See also:
The items on this page are in the following plugins: MBS Util Plugin.
