Expand/Shrink

c_proc

Definition: c_proc(integer rid, sequence args={})
Description: Call a C function.

rid must be a result from define_c_proc().
args is a sequence of argument values of length n, where n is the number of arguments required by the function.
pwa/p2js: Not supported.
Comments: If the C routine does not take any arguments then args should be {}.

If you pass an argument value which contains a fractional part, where the C function expects a C integer type, the argument is be rounded towards 0, for example 5.9 is passed as 5, -5.9 is passed as -5.

The C function could be part of a .dll or .so created via a format DLL/SO directive.

NB: While call_proc(id,args) can now be invoked via id(args), you cannot replace c_proc(rid,args) with rid(args).
Example:
atom hwnd, pRect = allocate_struct(idRect)
atom user32 = open_dll("user32.dll")
-- GetClientRect is a VOID C function that takes a C int
-- and a C pointer as its arguments:
integer GetClientRect = define_c_proc(user32, "GetClientRect", {C_INT, C_PTR})
-- pass hwnd and rect as the arguments
c_proc(GetClientRect, {hwnd, pRect})
Implementation: See builtins\VM\pcfunc.e (an autoinclude) for details of the actual implementation.
See Also: c_func, define_c_proc, open_dll, Calling C Functions