Inconsistent behavior of Julia ccall

Viewed 79

I'm attempting to use ccall to interface with a Windows function (FindWindowA to be specific), but i'm getting a weird behavior

julia> ccall((:FindWindowA, :user32), Int32, (Ptr{Cvoid},), C_NULL)
855386

julia> foo() = ccall((:FindWindowA, :user32), Int32, (Ptr{Cvoid},), C_NULL)
foo (generic function with 1 method)

julia> foo()
0

julia> @ccall :user32.FindWindowA(C_NULL::Ptr{Cvoid})::Int32
65920

julia> foo() = @ccall :user32.FindWindowA(C_NULL::Ptr{Cvoid})::Int32
foo (generic function with 1 method)

julia> foo()
0

Is there a way to get consistent results from ccall?

1 Answers

Try providing second parameter to the function as well, according to docs:

julia> @ccall :user32.FindWindowA(C_NULL::Ptr{Cvoid})::Int32
65896

julia> boo() = @ccall :user32.FindWindowA(C_NULL::Ptr{Cvoid}, C_NULL::Ptr{Cvoid})::Int32
boo (generic function with 1 method)

julia> boo()
65896
Related