Calling a platform function
An object of class PlatformFunction represents an external function. To create an instance of PlatformFunction, to call the function, and pass it the correct parameters, do the following:
1. Create an instance of PlatformFunction to represent the function you want to call. You must specify the following information:
callingConvention
The calling convention to use when calling the external function. The valid choices vary by platform.
function
The DLL entry point to call.
library
The name of the DLL containing the function.
parameterTypes
An array specifying the number and type of the parameters to pass to the function.
returnType
The type, if any, of the function's return value.
For example:
aPlatformFunction := PlatformFunction
callingConvention: 'c'
function: '_entrypoint'
library: 'DLLNAME'
parameterTypes: #( struct )
returnType: #none.
Creating functions manually contains a table that shows the supported calling conventions, their meaning, and the platforms supported.
2. Create an instance of the structure that will contain the input parameters.
aRecordStructure := MyRecordStructure new.
3. Set the values of the input parameters, using the generated setter methods. If the input parameter is a compound type, use the setter method provided for each field.
aRecordStructure inputParm1: 'Input Value 1'.
aRecordStructure inputParm2: 'Input Value 2'.
If a data field in a record structure is an array, there are additional methods in the basic, non parts-based part of VA Smalltalk which you can use to set the values of the items in the array. The method selectors are based on the names of the fields with At: or At:put: appended: For example, the following COBOL declaration:
01 Test PIC X OCCURS 5.
would result in the following generated selectors:
a. test
b. test:
c. testAt:
d. testAt:put:
4. Call the external function, passing to it the structure containing the input parameters.
aPlatformFunction coroutineCallWith: aRecordStructure
threadKey: nil.
The PlatformFunction method coroutineCallWith: calls the external function, passing it the parameters in the specified record structure. The argument threadKey: nil specifies that it should not run the function in a separate thread.
If you want to pass multiple record structures to the external function, you can use one of the following techniques:
a. The multiple-argument methods (such as coroutineCallWith:with: and coroutineCallWith:with:with:), which accept as many as 16 arguments
b. The coroutineCallWithArray: method, which accepts a single argument (an Array containing the record structures to be passed to the external function)
To call the sample external function, create a new application called MyExtFunc, specifying MySampleCExtFunc or MySampleCOBOLExtFunc as its prerequisite (depending on the language you are using). If you are working with the C sample, add SampleCATMConstants to the list of pool dictionaries in the class definition; for the COBOL sample, add SampleCOBOLATMConstants to the pool dictionaries in the class definition.
Last modified date: 09/30/2019