NOP Design Home Page
Documentation
TOC/Index
Search
Downloads



CallExternal

Calls a predefined function from an external operating system shared object or DLL

The CallExternal function runs a predefined function from an external operating system shared object or DLL. Parameters are passed based on their relative positions to the functions required parameters.

SIML String == C/C++ char*
SIML Integer == C/C++ long
SIML Number == C/C++ float

All parameter are passed by reference (using the & operator C++ style, or * operator C style) -- and are read/write.

You may allocate a single new string using the malloc or strdup commmands to return more data than was passed to you. If the string will not grow, you may use a strcpy. Integers and floats may not be re-allocated, but may be re-assigned.

SIML v.4.0 calling syntax and include files have been deprecated, and are no longer supported

Sample Source

#Declare some variables
strOne := "A first string"
strTwo := "A second string"
iThree := 123
fFour  := 12.2

# Load a pre-compiled shared object from the current path
LoadModule MyModule As RelativePath + "sample.so"


# Call a native C-style function within the shared object, or error if
# the function can not be found
iResult := CallExternal "MyFunction" From MyModule With strOne As String, \
              strTwo As String, iThree As Integer, fFour As Number
If iResult < 0 Then
   Say "ERROR, could not find function in shared object."
EndIf

Say "\nFunction returned: " + iResult

Say "\nstrOne = " + strOne
Say "\nstrTwo = " + strTwo
Say "\niThree = " + iThree
Say "\nfFour = " + fFour

Sample Source

/*
 *  sample.cpp
 *  C++ Sample function implementing external call above
 *  Build using the command:
 *    gcc -Wl,-rpath,. -fPIC -shared sample.cpp -o sample.so -ldl
 */
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>

extern "C" int sample( char*& strStringOne, char*& strString2, long& iThree, float& fFour )
{
   cout << "\nYou are seeing the module work!";
   cout << "\nString: ";
   cout << strStringOne ;
   cout << "\nInteger: ";
   cout << iThree;

   // We may allocate a new string value, but must allocate on the heap,
   // never point to local variables, stack variables, or constants.
   // SIML will free this value when the variable passed falls out of scope
	// C++ users should allocate with malloc, or strdup, NOT new.
   strStringOne = strdup("A new value!");

   //Integers / Floats may be reassigned
   iThree = 90210;

   return 0;
}

Sample Source

/*
 *  sample.c
 *  C Sample function implementing external call above
 *  Build using the command:
 *    gcc -Wl,-rpath,. -fPIC -shared sample.c -o sample.so -ldl
 */
#include <stdio.h>
#include <stdlib.h>

int sample( char** strStringOne, char** strString2, long*iThree, float *fFour )
{
   printf( "\nYou are seeing the module work!");
   printf( "\nString: ");
   printf( *strStringOne );
   printf( "\nInteger: ");
   printf( "%d", *iThree);

   /* We may allocate a new string value, but must allocate on the heap,
      never point to local variables, stack variables, or constants.
      SIML will free this value when the variable passed falls out of scope */
   *strStringOne = (char*)strdup("A new value!");

   /* Integers / Floats may be reassigned */
   *iThree = 90210;

   return 0;
}

Related Function(s):
   Call; LoadModule;

Minimum version: 4.8