JNAerator生成带有__stdcall返回值的方法

huangapple 未分类评论41阅读模式
英文:

JNAerator generates method with __stdcall return value

问题

我目前在为我必须使用的DLL生成JNA封装器而感到困扰。
这些DLL和相应的.h文件由IBM(Spectrum Protect,也称为Tivoli Storage Manager或ADSTAR)提供,但我无论如何都不能正确使用JNAerator。

示例:

以下是其中一个头文件的摘录:

extern dsInt16_t DSMLINKAGE dsmInitEx(
dsUint32_t *dsmHandleP,
dsmInitExIn_t *dsmInitExInP,
dsmInitExOut_t *dsmInitExOutP
);

而dsInt16_t原来是在单独的.h文件中定义的:

typedef signed short dsInt16_t;

运行JNAerator后的结果并不如我所预期:

Tsmapi64Library.__stdcall dsmInitEx(NativeLongByReference dsmHandleP, dsmInitExIn_t dsmInitExInP, dsmInitExOut_t dsmInitExOutP);

返回类型定义如下:

public static class __stdcall extends PointerType {
...
};

请注意,我上次使用C语言是在学校,那是20多年前的事情,所以我肯定有点生疏。

我在这里漏掉了什么?我本希望返回值是dsInt16_t或short,例如。

后续问题:DLL提供了一个解释返回代码(前面提到的dsInt16_t返回值)的方法。

同样,这是.h文件中的定义:

extern dsInt16_t DSMLINKAGE dsmRCMsg(
dsUint32_t dsmHandle,
dsInt16_t dsmRC,
char *msg
);

...这是生成的Java代码:

Tsmapi64Library.__stdcall dsmRCMsg(NativeLong dsmHandle, dsInt16_t dsmRC, ByteBuffer msg);

因此,它将C参数类型dsInt16_t“翻译”为Java类型dsInt16_t,这很好。
由于这个Java类型dsInt16_t是一个接口,我该如何创建这个类型的实例以便我可以实际调用该方法?(我猜一旦第一个问题解决了,这个问题就会过时。)

英文:

I'm currently struggling to generate a JNA wrapper for a DLL that I have to use.
The DLL and the corresponding .h files are provided by IBM (Spectrum Protect aka Tivoli Storage Manager or ADSTAR) and for the life of me, I cannot use JNAerator properly, as it seems.

Example:

This is an excerpt of one of the header files:

extern dsInt16_t DSMLINKAGE  dsmInitEx(
       dsUint32_t            *dsmHandleP,
       dsmInitExIn_t         *dsmInitExInP,
       dsmInitExOut_t        *dsmInitExOutP
);

This dsInt16_t turns out to be defined in a separate .h file:

typedef signed   short dsInt16_t;

The result after running JNAerator is not what I would have expected:

Tsmapi64Library.__stdcall dsmInitEx(NativeLongByReference dsmHandleP, dsmInitExIn_t dsmInitExInP, dsmInitExOut_t dsmInitExOutP);

The return type is defined as follows:

public static class __stdcall extends PointerType {
...
};

Mind you, last time I worked with C was in school, and that is 20+ years ago, so I am definitely a bit rusty.

What am I missing here? I would have hoped that the return value would be a dsInt16_t or short, for example.

A follow-up question: the DLL provides a method for explaining return codes (the aforementioned dsInt16_t return value).

Again, this is the definition in the .h file:

extern dsInt16_t DSMLINKAGE  dsmRCMsg(
       dsUint32_t            dsmHandle,
       dsInt16_t             dsmRC,
       char                  *msg
);

...and this is the resulting Java code:

Tsmapi64Library.__stdcall dsmRCMsg(NativeLong dsmHandle, dsInt16_t dsmRC, ByteBuffer msg);

So, it "translated" the C-parameter type dsInt16_t into the Java type dsInt16_t, which is nice.
Since this Java type dsInt16_t is an interface, how would I be able to create an instance of this type so that I could actually call the method? (I guess this question is obsolete once the first one is resolved.)

huangapple
  • 本文由 发表于 2020年4月8日 03:24:28
  • 转载请务必保留本文链接:https://java.coder-hub.com/61087864.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定