diff --git a/src/functionloading.jl b/src/functionloading.jl index 74e9e73..24e7d4e 100644 --- a/src/functionloading.jl +++ b/src/functionloading.jl @@ -33,6 +33,10 @@ function debug_opengl_expr(func_name, args) end end +# On 32-bit Windows, OpenGL functions use stdcall calling convention (APIENTRY). +# On 64-bit Windows (and all other platforms), there is only one calling convention. +const _gl_calling_convention = (Sys.iswindows() && Sys.WORD_SIZE == 32) ? :stdcall : :cdecl + # based on getCFun macro macro glfunc(opengl_func) arguments = map(opengl_func.args[1].args[2:end]) do arg @@ -47,6 +51,7 @@ macro glfunc(opengl_func) func_name_sym = Expr(:quote, func_name) func_name_str = string(func_name) ptr_expr = :(getprocaddress_e($func_name_str)) + cc = _gl_calling_convention if Sys.iswindows() # windows has some function pointers statically available and some not, this is how we deal with it: ptr = Libdl.dlsym_e(gl_lib, func_name) @@ -54,7 +59,7 @@ macro glfunc(opengl_func) ptr_expr = :(($func_name_sym, "opengl32")) ret = quote function $func_name($(arg_names...)) - result = ccall($ptr_expr, $return_type, ($(input_types...),), $(arg_names...)) + result = ccall($ptr_expr, $(cc), $return_type, ($(input_types...),), $(arg_names...)) $(debug_opengl_expr(func_name, arg_names)) result end @@ -70,7 +75,7 @@ macro glfunc(opengl_func) if $ptr_sym[]::Ptr{Cvoid} == C_NULL $ptr_sym[]::Ptr{Cvoid} = $ptr_expr end - result = ccall($ptr_sym[]::Ptr{Cvoid}, $return_type, ($(input_types...),), $(arg_names...)) + result = ccall($ptr_sym[]::Ptr{Cvoid}, $(cc), $return_type, ($(input_types...),), $(arg_names...)) $(debug_opengl_expr(func_name, arg_names)) result end