Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling Win32 Functions From Julia

Tags:

winapi

julia

I would like to call File I/O functions (i.e. CreateFile, WriteFile etc) from julia using ccall.

Do I have to indicate a library name as a parameter in ccall to call any function from win32 api? If yes, how can I determine the name of the corresponding dll?

like image 274
tantuni Avatar asked Oct 25 '25 15:10

tantuni


1 Answers

Yes you do need to supply a library name. The first argument to ccall is a tuple of the form (:function, "library"). So, if you were calling GetTickCount it would be (:GetTickCount, "kernel32").

You also need to specify the calling convention, return value type, and the parameter types. In the case of GetTickCount it would be:

tickCount = ccall( (:GetTickCount, "kernel32"), stdcall, UInt32, () )

To find out the calling convention, return value type, and the parameter types, look up the function on MSDN. For instance, GetTickCount is here: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724408.aspx. Notice that at the very bottom of the page is a table which contains the name of the library which exports the function. In this case, kernel32.

It's all covered in some detail here: http://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code/

like image 57
David Heffernan Avatar answered Oct 27 '25 16:10

David Heffernan