I'm trying to implement a Julia Wrapper for a C API I'm using. For instance : I've got the following prototype :
int32 foo(int32 BrdType, int32 BrdNumber, Bd *pBrdHandle)
.
Base on the source code the definition of Bd
is typedef void ***Bd;
Bd
will then be used later to manipulate my hardware (for instance with int32 otherfoo(Bd BrdHandle)
)
What I tried in julia
Currently, I can call my foo function in julia, but I'm not able to deference my pointer...
function fooWrap()
#function Pointer
lib = dlopen(find_library("foo.dll"))
func = dlsym(lib, "foo")
#Argument
BrdType = -1
BrdNumber = 0
pBrdHandle = Ref{Ptr{Cvoid}}()
#Output
result = ccall(func, Cint, (Cint, Cint, Ptr{Cvoid}), BrdType, BrdNumber, pBrdHandle)
println("result : ", result)
BrdHandle = unsafe_load(pBrdHandle)
return BrdHandle
end
(NB : the unsafe_load
function gave me the following error :
ERROR: MethodError: no method matching unsafe_load(::Base.RefValue{Ptr{Nothing}})
Closest candidates are:
unsafe_load(::Ptr) at pointer.jl:105
unsafe_load(::Ptr, ::Integer) at pointer.jl:105
So how should I do to "transform" my pBrdHandle
into BrdHandle
?
Thanks a lot for your help :)
EDIT
For clarity purpose, here are the "real" signature of the function :
BIRC BiBrdOpen(BFU32 BrdType, BFU32 BrdNumber, Bd *pBrdHandle)
BIRC BiBrdClose(Bd Board)
with typedef unsigned __int32 BFU32;
, typedef BFU32 BFRC;
and typedef void ***Bd;