ForeignFunction

ForeignFunction[args]

represents a function that has been loaded from a library.

Details

  • ForeignFunction objects are returned by functions like ForeignFunctionLoad.
  • The function represented by ForeignFunction runs in the same process as the Wolfram Language kernel.
  • The function represented by ForeignFunction can share data with the Wolfram Language kernel.
  • The function represented by ForeignFunction is unloaded when the Wolfram Language kernel exits.
  • Information for a ForeignFunction may include the following properties:
  • "ArgumentTypes"types of arguments
    "File"name of the library file
    "Function"name of the loaded function
    "ReturnType"return type
    "Type"full type
    "FunctionPointer"memory address
  • Arguments expecting a pointer type can also be passed a ManagedObject containing a pointer.
  • ForeignFunction objects loaded in one kernel session may not be valid in another.

Examples

open allclose all

Basic Examples  (1)

Load a function from a library:

Call the function:

Scope  (1)

Get information about a foreign function:

Possible Issues  (1)

ForeignFunction will return $Failed if arguments of the wrong type are passed to it:

Wolfram Research (2023), ForeignFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/ForeignFunction.html.

Text

Wolfram Research (2023), ForeignFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/ForeignFunction.html.

CMS

Wolfram Language. 2023. "ForeignFunction." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ForeignFunction.html.

APA

Wolfram Language. (2023). ForeignFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ForeignFunction.html

BibTeX

@misc{reference.wolfram_2024_foreignfunction, author="Wolfram Research", title="{ForeignFunction}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/ForeignFunction.html}", note=[Accessed: 27-April-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_foreignfunction, organization={Wolfram Research}, title={ForeignFunction}, year={2023}, url={https://reference.wolfram.com/language/ref/ForeignFunction.html}, note=[Accessed: 27-April-2024 ]}