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?
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With