DefineDLLFunction["func", "dll", rtype, atypes]
returns a Mathematica function that calls the specified function func with argument types atypes and return type rtype in the specified unmanaged DLL dll.

lets you write a full C#-syntax 'extern' function declaration. Use this form when you need to write a complex function declaration that requires features not available using options to DefineDLLFunction, such as specific "MarshalAs" attributes on each of the parameters.


  • To use DefineDLLFunction, you first need to load .NET/Link using Needs["NETLink`"].
  • The following options can be given:
  • CallingConventionAutomaticthe calling convention expected by the DLL function (possible values are "", "", "", and Automatic.)
    MarshalStringsAshow string arguments (char*, string, String) should be marshaled to and from the DLL function (possible values are "", "", and Automatic)
    ReferencedAssembliesAutomatica list of the names of assemblies referenced by your declaration
  • The atypes argument is a list of type specifications for the arguments, and can be omitted if the function takes no arguments.
  • The argument type and return type specifications are strings or, less commonly, NETType expressions.
  • Strings can be given in C-style syntax (such as ), C#-syntax (), Visual Basic .NET syntax (), or by using many Windows API types (such as , , , and so on).
  • Priority is given to the C interpretation of type names, so and have their meanings in C (1 and 4 bytes, respectively), not C#.
  • You need to give the full pathname to the DLL if it is not located in a standard location (standard locations are a directory on your system PATH or a DLL subdirectory in a Mathematica application directory, such as $InstallationDirectory\AddOns\Applications\SomeApp\DLL).
New to Mathematica? Find your learning path »
Have a question? Ask support »