CreateForeignCallback

CreateForeignCallback[f,type]

creates a foreign callback with the specified type that can be called from external libraries.

Details

  • CreateForeignCallback returns a managed ForeignCallback object.
  • Possible argument and return types and their corresponding C types include:
  • "UnsignedInteger8"uint8_tunsigned 8-bit integer
    "Integer8"int8_tsigned 8-bit integer
    "UnsignedInteger16"uint16_tunsigned 16-bit integer
    "Integer16"int16_tsigned 16-bit integer
    "UnsignedInteger32"uint32_tunsigned 32-bit integer
    "Integer32"int32_tsigned 32-bit integer
    "UnsignedInteger64"uint64_tunsigned 64-bit integer
    "Integer64"int64_tsigned 64-bit integer
    "CUnsignedChar"unsigned charC-compatible unsigned char
    "CSignedChar"signed charC-compatible signed char
    "CUnsignedShort"unsigned shortC-compatible unsigned short
    "CShort"shortC-compatible short
    "CUnsignedInt"unsigned intC-compatible unsigned int
    "CInt"intC-compatible int
    "CUnsignedLong"unsigned longC-compatible unsigned long
    "CLong"longC-compatible long
    "CSizeT"size_tC-compatible size_t
    "CFloat"floatC-compatible float
    "CDouble"doubleC-compatible double
    "OpaqueRawPointer"void*opaque pointer
    "RawPointer"::[t]t*typed pointer
    {ty1,ty2,}struct {ty1 f1; ty2 f2; }struct or product type
    "Void"voidno output (only in output types)

Examples

Basic Examples  (1)

Load a foreign function that takes a function pointer:

Create a foreign callback function:

Call the foreign function and pass the foreign callback:

02
0
12
1
22
4
32
9
42
16
52
25
62
36
72
49
82
64
92
81

Read the output:

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

Text

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

CMS

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

APA

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

BibTeX

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

BibLaTeX

@online{reference.wolfram_2024_createforeigncallback, organization={Wolfram Research}, title={CreateForeignCallback}, year={2023}, url={https://reference.wolfram.com/language/ref/CreateForeignCallback.html}, note=[Accessed: 21-November-2024 ]}