Calling a PlatformFunction
Once a PlatformFunction has been created, it can be called using call, callWith:, callWith:with:, and so on. The number of arguments in the call must match the number of arguments in the PlatformFunction.
For example, to call the MessageBox function described above, you might use the following statement:
"Open a default system owned message box with the caption 'Hello MessageBox'
and 'Hello Smalltalk!' as the message"
rc := messageBox
callWith: 0
with: 'Hello Smalltalk!' asPSZ
with: 'Hello MessageBox' asPSZ
with: 0
 
Use the callWithArguments:returnValue if you need to return a struct-by-value.
For example,
structInst := <OSStructure subclass> new.
rc := platformFunction callWithArguments: #(‘Testing’) returnValue: structInst
Error cases
The call to a PlatformFunction can fail and cause a walkback for the following reasons:
Invalid argument count
The number of parameters in the PlatformFunction is not the same as the number of parameters in the call.
Invalid class
The parameter could not be converted because its class is invalid (for example, trying to pass a Float in an int32 parameter). All such type conversions must be done explicitly (for example, pass the Float truncated as the parameter).
Value out of range
The Character or Integer value is not in the range allowed for the type (see above for the ranges).
Not enough memory
There is insufficient memory to allocate a LargeInteger for the return value of the function.
Operating system error
An operating-system-specific error occurred; for example, it could not find the shared library or the function in the library.
Note:
Calling a PlatformFunction with invalid arguments may result in a system crash. You need to ensure the validity of the arguments.
Last modified date: 11/05/2019