c - Julia ccall 的不一致行为

标签 c windows julia

我正在尝试使用 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 获得一致的结果?

最佳答案

根据 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

关于c - Julia ccall 的不一致行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65502320/

相关文章:

function - 在 Julia 的 for 循环中索引函数的名称

arrays - 手动展开 3 个嵌套循环 (Julia)

以方便的方式返回两个矩阵的函数

windows - 如何在 Windows 上安装 mongoDB?

iphone - 在 viewDidLoad 中的子类之后, [super viewDidLoad] 被调用,但方法没有被执行

c - 尝试在 C 中通过 newton raphson 方法找到近似根?

c - 尝试释放内存时免费抛出错误

windows - 有什么工具可以将 32 位/64 位可执行文件打包在一起吗?

c - 运行程序时出现错误#include <czmq.h>丢失

c - printf newline 有行缓冲区吗?