JNA 无符号整数引用给出了奇怪的结果

发布于 2024-09-01 13:40:20 字数 751 浏览 1 评论 0原文

我目前正在尝试使用 JNA 访问 C API。但我对通过引用传递的无符号整数参数有问题。

所以这里是有问题的 C 函数:

int EE_DataGetNumberOfSample(DataHandle hData, unsigned int* nSampleOut);

在 Java 中我有:

public int EE_DataGetNumberOfSample(Pointer hData, ByReference nSampleOut);

下面是我如何使用它:

IntByReference nSamplesTaken = new IntByReference();

edk.EE_DataGetNumberOfSample(hData.getValue(), nSamplesTaken);

int nativeNSamplesTaken = nSamplesTaken.getValue();

System.out.println(Integer.toBinaryString(nativeNSamplesTaken)+"("+nativeNSamplesTaken+")");

这给了我:

11000100110110010011000000(51602624)

虽然它应该是0。

我使用JNA-API的方式有问题吗?

谢谢你!

I'm currently trying to access a C API using JNA. But I have a problem with unsigned integer parameters that are being passed by reference.

So here is the C function in question:

int EE_DataGetNumberOfSample(DataHandle hData, unsigned int* nSampleOut);

In Java I have:

public int EE_DataGetNumberOfSample(Pointer hData, ByReference nSampleOut);

And here's how I'm using it:

IntByReference nSamplesTaken = new IntByReference();

edk.EE_DataGetNumberOfSample(hData.getValue(), nSamplesTaken);

int nativeNSamplesTaken = nSamplesTaken.getValue();

System.out.println(Integer.toBinaryString(nativeNSamplesTaken)+"("+nativeNSamplesTaken+")");

This gives me:

11000100110110010011000000(51602624)

Altough it should be 0.

Is there something wrong with the way I'm using the JNA-API?

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

口干舌燥 2024-09-08 13:40:20

回答我自己的问题:

我在这里发布的代码片段没有任何问题,但还有另一个完全不相关的错误,与问题无关。

[关闭]

To answer my own question:

There's nothing wrong with the code snippets I posted here, but there was another completely unrelated error that has nothing to do with the question.

[closed]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文