0

我们正在使用 jniwrapper 从 JAVA 与第 3 方 DLL 进行通信。DLL 希望我们将指针作为 uint64_t 传递给回调函数。

typedef struct random_struct { 
...
uint64_t callback;  //!< A function pointer to the callback
..
}

因此,从jniwrapper中,我尝试使用 Void、Pointer 等从 Java 映射,但这些都不起作用。DLL 抱怨回调设置无效。所以我的问题是如何将回调作为 uint64_t 进行通信。有没有人使用 Jniwrapper 来满足这样的需求?谢谢

4

1 回答 1

1

一个适当的回调函数将是:

[returnType] (*[nameOftheFunctionPtr])([parameters...]);

例子:


typedef uint8_t (*dataReader_t)(uint8_t* const buffer, uint8_t length);


typedef struct random_struct { 

    dataReader_t callback;  //!< A function pointer to the callback

}


您可以拥有以下将分配给回调的函数:

uint8_t ucReadFromBuffer(uint8_t* const buffer, uint8_t length){

// do stuff ...
// return uint8_t variable

}

然后你可以在你的代码中分配它:

random_struct myStruct = {.callback = ucReadFromBuffer};

// and if you want to call it
myStruct.callback(someBuffer, length);
// similar to
ucReadFromBuffer(someBuffer, length);
于 2021-10-07T06:31:43.927 回答