external_define

此函数可用于定义对特定dll(适用于Windows)或dylib(适用于Mac)的外部函数调用。此文件可以是包含的文件或扩展名的一部分。

您提供文件的名称(和路径),然后是您要定义的函数的名称。接下来,您需要定义要使用的调用约定(请参阅下面的常量列表)以及要预期的结果类型(也是一个常量,如下所列)。

最后,您必须给出函数可以接受的参数数量(从0到15),并且对于每个参数,您也必须指定其类型。请注意,对于具有4个或更多参数的函数,所有参数都必须是ty_real类型。

注意:这仅适用于已作为"包含文件"添加到GameMakerIDE的dll或dylib。它不适用于作为扩展添加的那些文件,因为这些文件需要您在扩展包本身中定义函数。

外部调用类型常量
常量描述
dll_cdeclThis is the default C, C++ call
dll_stdcallThis is the standard WinAPI call (Windows dll only)
外部数据类型常量
常量描述
ty_realA real number argument
ty_stringA null-terminated string argument

 

语法:

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

参数类型描述
dllStringDLL文件的名称(字符串)
nameString函数的名称(字符串)
calltypeExternal Call Type Constant (dll_*)使用的调用约定
restypeExternal Data Type Constant (ty_*)预期结果的类型
argnumbReal参数的数量(0-10)
argtype[0 ... 10]External Data Type Constant (ty_*)所使用的参数的类型

 

 

返回:

External Function

 

例子:

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

上面的示例代码将定义一个名为"MyMin"的外部函数,其中包含两个参数。