我有一个用 C++ 编写的 DLL,我无法更改。它具有以下暴露功能
// c++
DllExport unsigned int ProcessMessage( char * in_message, USHORT in_message_length, char * connectionString, bool ( SendMessage)( char * connectionString, BYTE * payload, USHORT iPayloadSize ) );
我有一个需要调用此 DLL 函数的 Java 应用程序。我目前正在使用 java 库com.sun.jna
// Java
public class main {
public interface CBlargAPI extends Library {
interface sendMessage_t extends Callback {
boolean invoke(String connectionString, Pointer payload, short iPayloadSize );
}
int ProcessMessage( byte[] in_message, short in_message_length, String connectionString, sendMessage_t SendMessage ) ;
}
public static void main(String[] args) throws Exception
{
// Override function thingy (#A)
CBlarg.sendMessage_t sendMessage_fn = new CBlarg.sendMessage_t() {
@Override
public boolean invoke(String connectionString, Pointer payload, short iPayloadSize) {
System.out.println("sendMessage_t: " ) ;
return false;
}
};
}
CBlargAPI.INSTANCE.ProcessMessage( receivePacket.getData(), (short) receivePacket.getLength(), connectionString, sendMessage_fn );
}
// static member function (#B)
public static boolean SendUDPMessage( String connectionString, Pointer payload, short length ) {
// ToDo: I want to use this one.
}
}
目前这正在使用,override function thingy (#A)
但我想static member function (#B)
改用。我尝试了一些没有成功的事情,例如
// Errors with "cannot find symbol, symbol: class SendUDPMessage, location: class main"
CBACnetAPI.sendMessage_t sendMessage_fn = new main.SendUDPMessage();
我是初级 C++ 程序员,很少接触 Java
我的问题是:
- 我如何调用静态成员函数
SendUDPMessage()
作为回调而不是Override function thingy (#A)
?