0
我有一個用C++編寫的DLL,我無法更改。它具有以下暴露功能來自C++應用程序的Java com.sun.jna回調函數
// c++
DllExport unsigned int ProcessMessage(char * in_message, USHORT in_message_length, char * connectionString, bool (SendMessage)(char * connectionString, BYTE * payload, USHORT iPayloadSize) );
我有一個Java應用程序需要調用此DLL函數。我目前使用的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)
?
我只是想讓班級設置得更乾淨。 –