我如何将这个 Delphi 函数与 JNA 映射
我有以下 Delphi 函数:
function DoX(const InputBuffer: Pointer; const InputBufferSize: longword; OutputBuffer: Pointer; var OutputBufferSize: longword): longbool;
OutputBuffer 和 OutputBufferSize 将在函数中设置为结果的一部分,并使用布尔值返回来指示该方法是否成功(InputBuffer 和 OutputBuffer 将是字节数组)。
我已经成功地使用 JNA 从 dll 映射了一些我需要的函数,并且它们工作正常,但是这个函数给我带来了问题,任何帮助将不胜感激。
I have the following Delphi function:
function DoX(const InputBuffer: Pointer; const InputBufferSize: longword; OutputBuffer: Pointer; var OutputBufferSize: longword): longbool;
The OutputBuffer and OutputBufferSize would be set in the function as part of the result, with a boolean return to indicate whether the method was successful (InputBuffer & OutputBuffer would be byte arrays).
I have managed to map some of my required functions from the dll with JNA and they are working ok, however this one is giving me issues, any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
大多数 JNA 文档假设您使用的是 C,而不是 Delphi,因此从与该函数等效的 C 开始:
您还需要正确的调用约定。 Delphi 的默认设置是注册,这可能不是您想要的。 使用stdcall来代替; 这就是其他所有 DLL 所使用的。
Java 没有与您使用的类型等效的无符号类型,因此首先忽略无符号。 这使得
InputBufferSize
成为int
。 您的函数返回布尔结果,因此请使用boolean
作为其返回类型。 JNA 支持通过的后代通过引用传递类型ByReference
类,因此使用OutputBufferSize
的IntByReference
。最后是指针。 你说它们是字节数组,所以我很困惑为什么你不在 Delphi 代码中这样声明它们。 使用
PByte
,或者声明一个新的PByteArray
类型并使用它。 (这一更改将使该函数的实现更加方便。)在 Java 中,尝试将它们声明为字节数组。 所以,最终产品:Most JNA documentation assumes you're using C, not Delphi, so start with the C equivalent to that function:
You'll also want to get the calling convention right. Delphi's default is register, which probably isn't what you want. Use stdcall instead; that's what every other DLL uses.
Java doesn't have unsigned type equivalents to the ones you used, so start by ignored the unsignedness. That makes
InputBufferSize
anint
. Your function returns a Boolean result, so useboolean
for its return type. JNA supports passing types by reference through descendants of theByReference
class, so useIntByReference
forOutputBufferSize
.Finally are the pointers. You said they're byte arrays, so I'm puzzled why you don't declare them that way in your Delphi code. Either use
PByte
, or declare a newPByteArray
type and use that. (That change will make implementing that function much more convenient.) In Java, try declaring them as byte arrays. So, the final product: