CFunction.Call
--------------

Calls a C function.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [CFunction](component_CFunction.md) | [10.3](newinversion103.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "CFunction.Call"; FunctionRef; Parameters... ) 

**MBS**( **"CFunction.Call";** /\* Calls a C function. \*/  
**$FunctionRef**; /\* The reference number for the function.e.g. $func \*/   
**$Parameters...**) /\* The parameters.  
Pass one for each value, see examples. \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| FunctionRef | The reference number for the function. | $func |
| Parameters... | The parameters.   Pass one for each value, see examples. |  |

### Result

Returns OK or error.

### Description

Calls a C function.  
Pass a FileMaker parameter for each parameter.  
For pointer parameter, you can use Function.AllocateArray to pass an array as parameter. The passed value is then ignored and we pass pointer to array.  
  
This function takes variable number of parameters. Pass as much parameters as needed separated by the semicolon in FileMaker.  
Please repeat Parameters parameter as often as you need.  
### Examples

Call a function without parameters:

 MBS ( "CFunction.Call"; $function )  
Load SQLite version function and run it:

 Set Variable \[ $library ; Value: MBS ( "[CLibrary.Load](CLibraryLoad.md)"; "/usr/lib/libsqlite3.dylib" ) \]   
If \[ MBS ("IsError") \]   
 Show Custom Dialog \[ "Failed to load library." ; $library \]   
Else  
 Set Variable \[ $function ; Value: MBS ( "[CLibrary.LoadFunction](CLibraryLoadFunction.md)"; $library ; "sqlite3\_libversion"; "()Z" ) \]   
 If \[ MBS ("IsError") \]   
 Show Custom Dialog \[ "Failed to load function." ; $function \]   
 Else  
 Set Variable \[ $version ; Value: MBS ( "CFunction.Call"; $function ) \]   
 Show Custom Dialog \[ "SQLite version:" ; $version \]   
 Set Variable \[ $r ; Value: MBS ( "[CFunction.Release](CFunctionRelease.md)"; $function ) \]   
 End If  
 Set Variable \[ $r ; Value: MBS ( "[CLibrary.Release](CLibraryRelease.md)"; $library ) \]   
End If  
Query user name on Windows:

 # this is C declaration:   
\# BOOL GetUserNameW(LPWSTR lpBuffer, LPDWORD pcbBuffer);   
\#   
\# we load the library and the function   
Set Variable \[ $library ; Value: MBS ( "[CLibrary.Load](CLibraryLoad.md)"; "Advapi32.dll") \]   
If \[ MBS ("IsError") \]   
 Show Custom Dialog \[ "Failed to load library." ; $library \]   
Else  
 Set Variable \[ $function ; Value: MBS ( "[CLibrary.LoadFunction](CLibraryLoadFunction.md)"; $library ; "GetUserNameW"; "(pp)i") \]   
 If \[ MBS ("IsError") \]   
 Show Custom Dialog \[ "Failed to load library." ; $function \]   
 Else  
 # since 1st parameter is WChar Array, we allocate space for it  
 Set Variable \[ $r ; Value: MBS ( "[CFunction.AllocateArray](CFunctionAllocateArray.md)"; $function ; 0; "S"; 256 ) \]   
 # and for the count variable as ptr, we allocate a one value array  
 Set Variable \[ $r ; Value: MBS ( "[CFunction.AllocateArray](CFunctionAllocateArray.md)"; $function ; 1; "I"; 1) \]   
 # put in 255 for the length of the first array (minus one character for end character)  
 Set Variable \[ $r ; Value: MBS ( "[CFunction.SetArray](CFunctionSetArray.md)"; $function ; 1; "i"; 255) \]   
 # Now call function  
 Set Variable \[ $result ; Value: MBS ( "CFunction.Call"; $function ) \]   
 If \[ $result = 1 \]   
 # now we read how many characters we got  
 Set Variable \[ $r ; Value: MBS ( "[CFunction.GetArray](CFunctionGetArray.md)"; $function ; 1; "I") \]   
 Set Variable \[ $length ; Value: GetValue($r ; 1) \]   
 # and get the characters  
 Set Variable \[ $characters ; Value: MBS ( "[CFunction.GetArray](CFunctionGetArray.md)"; $function ; 0; "S") \]   
 #   
 # we loop over the values to build the text  
 Set Variable \[ $text ; Value: "" \]   
 Set Variable \[ $index ; Value: 1 \]   
 Loop \[ Flush: Always \]  
 Set Variable \[ $char ; Value: GetValue($characters ; $index ) \]   
 Set Variable \[ $text ; Value: $text &amp; Char($char ) \]   
 #   
 Set Variable \[ $index ; Value: $index + 1 \]   
 Exit Loop If \[ $index = $length \]   
 End Loop  
 #   
 Show Custom Dialog \[ "Windows user name" ; $text \]   
 #   
 # cleanup  
 Set Variable \[ $r ; Value: MBS ( "[CFunction.FreeArray](CFunctionFreeArray.md)"; $function ; 0) \]   
 Set Variable \[ $r ; Value: MBS ( "[CFunction.FreeArray](CFunctionFreeArray.md)"; $function ; 1) \]   
 End If  
 Set Variable \[ $r ; Value: MBS ( "[CFunction.Release](CFunctionRelease.md)"; $function ) \]   
 End If  
 Set Variable \[ $r ; Value: MBS ( "[CLibrary.Release](CLibraryRelease.md)"; $library ) \]   
End If  
### See also

- [CFunction.AllocateArray](CFunctionAllocateArray.md)
- [CFunction.FreeArray](CFunctionFreeArray.md)
- [CFunction.GetArray](CFunctionGetArray.md)
- [CFunction.Name](CFunctionName.md)
- [CFunction.Release](CFunctionRelease.md)
- [CFunction.SetArray](CFunctionSetArray.md)
- [CLibrary.Load](CLibraryLoad.md)
- [CLibrary.LoadFunction](CLibraryLoadFunction.md)
- [CLibrary.Release](CLibraryRelease.md)
- [IsError](IsError.md)

### Blog Entries

- [Calling C functions from FileMaker](https://www.mbsplugins.de/archive/2024-01-09/Calling_C_functions_from_FileM/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 25th April 2020 , last changed 4th January 2024

  
[CFunction.AllocateArray](CFunctionAllocateArray.md) - [CFunction.FreeArray](CFunctionFreeArray.md)

[HTML Version](CFunctionCall.shtml)