【问题标题】:Inconsistent behavior of Julia ccallJulia ccall 的不一致行为
【发布时间】:2020-12-31 23:36:33
【问题描述】:

我正在尝试使用 ccall 与 Windows 函数交互(具体为 FindWindowA),但我遇到了一个奇怪的行为

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

有没有办法从 ccall 获得一致的结果?

【问题讨论】:

    标签: c windows julia


    【解决方案1】:

    尝试为函数提供第二个参数,根据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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-17
      • 1970-01-01
      • 2019-06-19
      • 2015-03-03
      • 2021-05-13
      • 1970-01-01
      相关资源
      最近更新 更多