external_define

This function can be used to define an external function call to a specific dll (for Windows) or dylib (for Mac). This file can be either an included file or part of an extension.

You supply the name (and path) of the file, then the name of the function that you wish to define. Next you need to define the calling convention to be used (see the constants list below) as well as the type of result to be expected (also a constant, as listed below).

Finally you must give the number of arguments that the function can take (from 0 to 15) and for each of the arguments you must specify its type too. Please note that for functions with 4 or more arguments, all of them must be of type ty_real.

NOTE: This is only for dll or dylib that have been added as "Included Files" to the GameMaker IDE. It will not work with those files added as extensions, since those require that you define the functions in the extension package itself.

External Call Type Constants
ConstantDescription
dll_cdeclThis is the default C, C++ call
dll_stdcallThis is the standard WinAPI call (Windows dll only)
External Data Type Constants
ConstantDescription
ty_realA real number argument
ty_stringA null-terminated string argument

 

Syntax:

external_define(dll, name, calltype, restype, argnumb, argtype[0], argtype[1], ...argtype[10]);

ArgumentTypeDescription
dllStringThe name of the DLL file (string)
nameStringThe name of the function (string)
calltypeExternal Call Type Constant (dll_*)The calling convention used
restypeExternal Data Type Constant (ty_*)The type of the result to expect
argnumbRealThe number of arguments (0 - 10)
argtype[0 ... 10]External Data Type Constant (ty_*)The types of the arguments being used

 

 

Returns:

External Function

 

Example:

my_funcion = external_define("MyDLL.dll", "MyMin", dll_cdecl, ty_real, 2, ty_real, ty_real);

The above example code will define an external function called "MyMin" with two arguments.